From 08493a24b75b580c5dd25464267bba1db6e43648 Mon Sep 17 00:00:00 2001 From: April Hall Date: Mon, 24 Feb 2025 15:34:02 -0500 Subject: [PATCH] fix: Add session checking in server layout --- src/routes/(main)/+layout.server.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/routes/(main)/+layout.server.ts b/src/routes/(main)/+layout.server.ts index 09721bc..4538e8d 100644 --- a/src/routes/(main)/+layout.server.ts +++ b/src/routes/(main)/+layout.server.ts @@ -2,6 +2,7 @@ import { db } from '$lib/server/db'; import { auth } from '$lib/server/db/auth'; import { authdb } from '$lib/server/db/sqlite.js'; import { newChannelSchema } from '$lib/types/misc'; +import { redirect } from '@sveltejs/kit'; import { superValidate } from 'sveltekit-superforms'; import { zod } from 'sveltekit-superforms/adapters'; @@ -11,6 +12,14 @@ interface Profile { } export async function load({ request }) { + const session = await auth.api.getSession({ + headers: request.headers, + }); + + if (!session) { + redirect(307, '/signup'); + } + const form = await superValidate(zod(newChannelSchema)); const rows = await db.getChannels(); const channels: string[] = rows @@ -19,10 +28,6 @@ export async function load({ request }) { }) : []; - const session = await auth.api.getSession({ - headers: request.headers, - }); - let user: Profile; if (session?.user.id) {