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 <no-reply@ona.com>
This commit is contained in:
2026-03-24 21:11:38 +00:00
committed by GitHub
parent 9b0ac1cd4e
commit 59d14ee37b

View File

@@ -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<ReturnType<typeof getSession>> | null = null
try {
session = await context.queryClient.ensureQueryData({
queryKey: ["session"],
queryFn: getSession,
})
} catch {
throw redirect({ to: "/login" })
}
if (!session?.user) {
throw redirect({ to: "/login" })
}