chore: preload nested deps

This commit is contained in:
Aslam H
2024-11-13 22:27:43 +07:00
parent 7eda38955e
commit a44cf910b2
23 changed files with 231 additions and 234 deletions

View File

@@ -2,12 +2,24 @@ import { createFileRoute, Outlet, redirect } from "@tanstack/react-router"
export const Route = createFileRoute("/_layout/_pages/_protected")({
beforeLoad: async ({ context, location }) => {
if (!context?.auth?.userId) {
// Add extra validation
if (!context || !context.auth) {
throw redirect({
to: "/sign-in/$",
search: { redirect_url: location.pathname },
})
}
const auth = await context.auth
if (!auth?.userId) {
throw redirect({
to: "/sign-in/$",
search: { redirect_url: location.pathname },
})
}
return context
},
component: () => <Outlet />,
})