From 9503f8d0aae505dad491ea0be8b4d546236faffe Mon Sep 17 00:00:00 2001 From: Valknar XXX Date: Tue, 28 Oct 2025 12:17:58 +0100 Subject: [PATCH] fix: add authentication guard to /me page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Redirect unauthenticated users to /login - Add error handling for getFolders API call - Prevent 500 errors from accessing undefined user properties This fixes the issue where clicking the header button to access the dashboard would show a 500 error for unauthenticated users. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../frontend/src/routes/me/+page.server.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/frontend/src/routes/me/+page.server.ts b/packages/frontend/src/routes/me/+page.server.ts index b68c5dd..075464a 100644 --- a/packages/frontend/src/routes/me/+page.server.ts +++ b/packages/frontend/src/routes/me/+page.server.ts @@ -1,19 +1,24 @@ +import { redirect } from "@sveltejs/kit"; import { getAnalytics, getFolders, getRecordings } from "$lib/services"; import { isModel } from "$lib/directus"; export async function load({ locals, fetch }) { - const recordings = locals.authStatus.authenticated - ? await getRecordings(fetch).catch(() => []) - : []; + // Redirect to login if not authenticated + if (!locals.authStatus.authenticated) { + throw redirect(302, "/login"); + } - const analytics = - locals.authStatus.authenticated && isModel(locals.authStatus.user) - ? await getAnalytics(fetch).catch(() => null) - : null; + const recordings = await getRecordings(fetch).catch(() => []); + + const analytics = isModel(locals.authStatus.user) + ? await getAnalytics(fetch).catch(() => null) + : null; + + const folders = await getFolders(fetch).catch(() => []); return { authStatus: locals.authStatus, - folders: await getFolders(fetch), + folders, recordings, analytics, };