feat: implement auth stores

This commit is contained in:
mrjvs
2026-08-07 13:16:43 +02:00
parent 1c10ac1df0
commit fb0efeb4ed
17 changed files with 667 additions and 21 deletions

View File

@@ -0,0 +1,22 @@
export type AuthContext = {
pid: number;
}
export function setAuthContext(event: H3Event, context: AuthContext) {
event.context.auth = context;
}
export function getAuthContext(event: H3Event): AuthContext | null {
return event.context.auth ?? null;
}
export function enforceLoggedIn(event: H3Event): AuthContext {
const context = getAuthContext(event);
if (!context) throw createError({
status: 401,
statusText: "This action requires authentication",
})
return context;
}