From 59d14ee37b790c42a2a75f8ca25eca79abeb4fd2 Mon Sep 17 00:00:00 2001 From: Kenneth Date: Tue, 24 Mar 2026 21:11:38 +0000 Subject: [PATCH] fix(admin-dashboard): redirect to login on session fetch failure (#93) Wrap the session check in beforeLoad with a try/catch so network errors, 404s, and other failures redirect to the login page instead of showing an error boundary. Co-authored-by: Ona --- apps/admin-dashboard/src/routes/_dashboard.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/admin-dashboard/src/routes/_dashboard.tsx b/apps/admin-dashboard/src/routes/_dashboard.tsx index e097b96..bfbf00b 100644 --- a/apps/admin-dashboard/src/routes/_dashboard.tsx +++ b/apps/admin-dashboard/src/routes/_dashboard.tsx @@ -47,10 +47,15 @@ export const Route = createRoute({ getParentRoute: () => rootRoute, id: "dashboard", beforeLoad: async ({ context }) => { - const session = await context.queryClient.ensureQueryData({ - queryKey: ["session"], - queryFn: getSession, - }) + let session: Awaited> | null = null + try { + session = await context.queryClient.ensureQueryData({ + queryKey: ["session"], + queryFn: getSession, + }) + } catch { + throw redirect({ to: "/login" }) + } if (!session?.user) { throw redirect({ to: "/login" }) }