You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
592 B
18 lines
592 B
import { isAuthenticated } from '@/utils/auth.ts'
|
|
import { createFileRoute, redirect } from '@tanstack/react-router'
|
|
|
|
export const AuthenticatedRoute = createFileRoute('/_authenticated')({
|
|
beforeLoad: async ({ location }) => {
|
|
if (!isAuthenticated()) {
|
|
throw redirect({
|
|
to: '/login',
|
|
search: {
|
|
// Use the current location to power a redirect after login
|
|
// (Do not use `router.state.resolvedLocation` as it can
|
|
// potentially lag behind the actual current location)
|
|
redirect: location.href,
|
|
},
|
|
})
|
|
}
|
|
},
|
|
})
|