mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-10-21 22:41:10 -05:00
feat: implement auth stores
This commit is contained in:
22
src/server/utils/enforceAuth.ts
Normal file
22
src/server/utils/enforceAuth.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user