deckhearth/pages/api
Randall Stillwell 1fca3aa1ca fix(api): return 401 (not 500) on unauthenticated cards-collection writes
Follow-up to fix-auth-bypass Brief 2 (commit 258e479). Brief 2 made
getUserFromRequest return null for unauthenticated requests. POST, PUT,
and DELETE branches of pages/api/collections/[identifier]/cards.js
were dereferencing user.userId without a guard → NPE → HTTP 500.

Security side was already fixed by Brief 2 (no more
anonymous-write-as-admin on collections owned by userId: 1). This patch
adds the cosmetic 500 → 401 cleanup the Brief 2 reviewer flagged.

Three identical 'if (!user) return 401' guards added, one per write
branch. GET branch was already guarded via the ternary pattern.

Sibling endpoints under pages/api/collections/** were re-audited by the
implementer and confirmed correctly guarded (thumbnails, permissions,
activity all have early null checks; [identifier].js uses optional
chaining throughout). No further hotfixes needed for that route group.

Convoy: fix-auth-bypass / Brief 6 (post-architect hotfix)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-23 11:04:55 -05:00
..
admin Major Scanner Improvements 2025-07-29 14:19:48 -05:00
auth fix(auth): tighten public auth surface — CORS + rate limit (Brief 4 of fix-auth-bypass) 2026-05-23 10:57:49 -05:00
cards Major Scanner Improvements 2025-07-29 14:19:48 -05:00
collections fix(api): return 401 (not 500) on unauthenticated cards-collection writes 2026-05-23 11:04:55 -05:00
community 🌍 Separate My Collections & Community Collections 2025-07-27 13:17:13 -05:00
config Major Scanner Improvements 2025-07-29 14:19:48 -05:00
decks Major Scanner Improvements 2025-07-29 14:19:48 -05:00
invite 🎉 COMPLETED: Full Collaborative Collections System 2025-07-25 08:34:28 -05:00
public Major Scanner Improvements 2025-07-29 14:19:48 -05:00
user 🖼️ Complete Avatar Upload System with Vercel Blob 2025-07-26 21:39:42 -05:00
users fix(auth): centralize JWT secret + 24h TTL (Brief 1 of fix-auth-bypass) 2026-05-23 10:40:50 -05:00
auth-utils.js fix(auth): centralize JWT secret + 24h TTL (Brief 1 of fix-auth-bypass) 2026-05-23 10:40:50 -05:00
collections.js 🔧 Fix SQL Template Literal Syntax Error 2025-07-27 20:00:20 -05:00
decks.js Major Scanner Improvements 2025-07-29 14:19:48 -05:00
favorites.js fix(auth): centralize JWT secret + 24h TTL (Brief 1 of fix-auth-bypass) 2026-05-23 10:40:50 -05:00
health.js Clean slate: Remove React traces and create pure Next.js setup 2025-07-23 09:32:31 -05:00
user-cards.js Major Scanner Improvements 2025-07-29 14:19:48 -05:00