minor session management refactors
This commit is contained in:
parent
7ae80f5e88
commit
6a14e2c538
@ -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);
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user