check user is present

A session can exist without a user, if the user was recently deleted
This commit is contained in:
Benjamin Palko 2024-12-20 11:02:48 -05:00
parent a4deed23fe
commit 3691bd6f8f
2 changed files with 4 additions and 9 deletions

View file

@ -11,7 +11,7 @@ export async function validateSession(event: ServerLoadEvent) {
where: { id: sessionId }, where: { id: sessionId },
include: { user: true }, include: { user: true },
}); });
if (!session) { if (!session || !session.user) {
redirect(300, '/login'); redirect(300, '/login');
} }
const expiry = session.expiresAt; const expiry = session.expiresAt;

View file

@ -1,10 +1,5 @@
import { validateSession } from '$lib/server/auth/index.js'; import { validateSession } from '$lib/server/auth/index.js';
export async function load(event) { export async function load(event) {
const { await validateSession(event);
user: { password: _, ...rest },
} = await validateSession(event);
return {
user: rest,
};
} }