fix(api): return 401 (not 500) on unauthenticated cards-collection writes #10

Merged
varutasu merged 1 commit from brief/fix-auth-bypass/6-cards-null-guard into main 2026-05-23 12:04:55 -04:00
Showing only changes of commit e391be92ad - Show all commits

View file

@ -99,6 +99,10 @@ export default async function handler(req, res) {
res.status(200).json({ cards });
} else if (req.method === 'POST') {
if (!user) {
return res.status(401).json({ error: 'Authentication required to modify this collection' });
}
// Add card to collection - only allow if user has write access
const canWrite = collection.user_id === user.userId ||
['owner', 'editor'].includes(collection.user_role);
@ -160,6 +164,10 @@ export default async function handler(req, res) {
`;
} else if (req.method === 'PUT') {
if (!user) {
return res.status(401).json({ error: 'Authentication required to modify this collection' });
}
// Update card quantity in collection
const canWrite = collection.user_id === user.userId ||
['owner', 'editor'].includes(collection.user_role);
@ -209,6 +217,10 @@ export default async function handler(req, res) {
`;
} else if (req.method === 'DELETE') {
if (!user) {
return res.status(401).json({ error: 'Authentication required to modify this collection' });
}
// Remove card from collection
const canWrite = collection.user_id === user.userId ||
['owner', 'editor'].includes(collection.user_role);