mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-25 11:21:17 +00:00
fix(admin-dashboard): redirect to login on session fetch failure
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:
@@ -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" })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user