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.

17 lines
592 B

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. import { isAuthenticated } from '@/utils/auth.ts'
  2. import { createFileRoute, redirect } from '@tanstack/react-router'
  3. export const AuthenticatedRoute = createFileRoute('/_authenticated')({
  4. beforeLoad: async ({ location }) => {
  5. if (!isAuthenticated()) {
  6. throw redirect({
  7. to: '/login',
  8. search: {
  9. // Use the current location to power a redirect after login
  10. // (Do not use `router.state.resolvedLocation` as it can
  11. // potentially lag behind the actual current location)
  12. redirect: location.href,
  13. },
  14. })
  15. }
  16. },
  17. })