mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-26 11:51: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,
|
getParentRoute: () => rootRoute,
|
||||||
id: "dashboard",
|
id: "dashboard",
|
||||||
beforeLoad: async ({ context }) => {
|
beforeLoad: async ({ context }) => {
|
||||||
const session = await context.queryClient.ensureQueryData({
|
let session: Awaited<ReturnType<typeof getSession>> | null = null
|
||||||
queryKey: ["session"],
|
try {
|
||||||
queryFn: getSession,
|
session = await context.queryClient.ensureQueryData({
|
||||||
})
|
queryKey: ["session"],
|
||||||
|
queryFn: getSession,
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
throw redirect({ to: "/login" })
|
||||||
|
}
|
||||||
if (!session?.user) {
|
if (!session?.user) {
|
||||||
throw redirect({ to: "/login" })
|
throw redirect({ to: "/login" })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user