minor session management refactors

This commit is contained in:
axel 2025-04-12 21:48:45 +02:00
parent 7ae80f5e88
commit 6a14e2c538
2 changed files with 5 additions and 14 deletions

View File

@ -33,7 +33,7 @@ export const init: ServerInit = async () => {
export async function handle({ event, resolve }) {
const { cookies, locals } = event;
locals.guard = new Guard(await getUserFromSession(cookies.get('session')));
locals.guard = new Guard(getUserFromSession(cookies.get('session')));
return await resolve(event);
}

View File

@ -15,22 +15,13 @@ export function createSession(data: SessionData) {
return token;
}
export async function getUserFromSession(sessionId?: string) {
if (!sessionId) {
return undefined;
}
export function getUserFromSession(sessionId?: string) {
if (!sessionId) return undefined;
const data = sessions.get(sessionId);
if (!data) return undefined;
if (!data) {
return undefined;
}
// what in the nested fuck is this shit
// I thought ORMs made it easier but they just make queries more ridiculous
const user = await db.data.users.find((u) => u.id === data.userId);
return user;
return db.data.users.find((u) => u.id === data.userId);
}
export function deleteSession(sessionId?: string) {