fix: add authentication guard to /me page

- 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 <noreply@anthropic.com>
This commit is contained in:
Valknar XXX
2025-10-28 12:17:58 +01:00
parent b8fdcb1193
commit 9503f8d0aa

View File

@@ -1,19 +1,24 @@
import { redirect } from "@sveltejs/kit";
import { getAnalytics, getFolders, getRecordings } from "$lib/services"; import { getAnalytics, getFolders, getRecordings } from "$lib/services";
import { isModel } from "$lib/directus"; import { isModel } from "$lib/directus";
export async function load({ locals, fetch }) { export async function load({ locals, fetch }) {
const recordings = locals.authStatus.authenticated // Redirect to login if not authenticated
? await getRecordings(fetch).catch(() => []) if (!locals.authStatus.authenticated) {
: []; throw redirect(302, "/login");
}
const analytics = const recordings = await getRecordings(fetch).catch(() => []);
locals.authStatus.authenticated && isModel(locals.authStatus.user)
const analytics = isModel(locals.authStatus.user)
? await getAnalytics(fetch).catch(() => null) ? await getAnalytics(fetch).catch(() => null)
: null; : null;
const folders = await getFolders(fetch).catch(() => []);
return { return {
authStatus: locals.authStatus, authStatus: locals.authStatus,
folders: await getFolders(fetch), folders,
recordings, recordings,
analytics, analytics,
}; };