Locked At The Door
A document app has this route pair. locals.user is populated by an auth hook on every request.
// src/routes/documents/[id]/+page.server.ts
export const load = async ({ params, locals }) => {
const doc = await db.query.documents.findFirst({
where: eq(documents.id, params.id)
})
if (!doc) error(404, 'not found')
if (doc.ownerId !== locals.user.id) error(403, 'forbidden')
return { doc }
}
// src/routes/api/documents/[id]/+server.ts
export const PATCH = async ({ params, request, locals }) => {
if (!locals.user) error(401, 'unauthenticated')
const body = await request.json()
await db.update(documents)
.set({ title: body.title })
.where(eq(documents.id, params.id))
return json({ ok: true })
}
A signed-in user who does not own d_91 opens a terminal. Which request succeeds?
Sign in to answer questions and track your progress
Sign In