mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-13 04:06:57 +02:00
refactor(api): scope all queries by authenticated user
Add getUserId/requireAdmin helpers in api-utils.ts. All notes, tags, search, sync, and attachment routes now filter by userId to ensure complete data isolation between users. Sync server accepts userId parameter for push/pull operations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Fred Cabassut
co-authored by
Claude Opus 4.6
parent
875306c99a
commit
c9e041bffe
@@ -0,0 +1,12 @@
|
||||
import { error, type RequestEvent } from '@sveltejs/kit';
|
||||
|
||||
export function getUserId(event: RequestEvent): number {
|
||||
if (!event.locals.user) throw error(401, 'Unauthorized');
|
||||
return event.locals.user.id;
|
||||
}
|
||||
|
||||
export function requireAdmin(event: RequestEvent) {
|
||||
const user = event.locals.user;
|
||||
if (!user || user.role !== 'admin') throw error(403, 'Forbidden');
|
||||
return user;
|
||||
}
|
||||
Reference in New Issue
Block a user