fix(api): return 401 (not 500) on unauthenticated cards-collection writes #10
1 changed files with 12 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue