feat: scope every API endpoint to the token's sub; expose ownerId in DTOs
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// PUT /api/tasks/:id (desktop) — idempotent upsert mirroring a desktop Idle task.
|
||||
// PUT /api/tasks/:id (desktop) — idempotent upsert mirroring a desktop Idle task, owned by the caller.
|
||||
export default defineEventHandler(async (event) => {
|
||||
const id = getRouterParam(event, "id")!;
|
||||
const body = await readBody(event);
|
||||
@@ -9,12 +9,13 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
const description = typeof body?.description === "string" ? body.description : null;
|
||||
|
||||
const ownerId = ownerOf(event);
|
||||
const sql = getSql();
|
||||
if (!(await listExists(sql, listId))) {
|
||||
if (!(await listExists(sql, ownerId, listId))) {
|
||||
throw createError({ statusCode: 404, statusMessage: "list not found" });
|
||||
}
|
||||
|
||||
const { created } = await upsertDesktopTask(sql, id, { listId, title, description });
|
||||
const { created } = await upsertDesktopTask(sql, ownerId, id, { listId, title, description });
|
||||
setResponseStatus(event, created ? 201 : 200);
|
||||
return { id };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user