Route guards live in src/utils/route-guard/. They redirect based on useAuth().isLoggedIn.

AuthGuard — AuthGuard.tsx

Protects routes that require authentication.
  • Redirects unauthenticated users to /login
  • Preserves intended path in location.state.from for post-login return
Always renders children (redirect is async via effect).

GuestGuard — GuestGuard.tsx

Protects login/register pages from authenticated users.
  • APP_DEFAULT_PATH = /dashboard from config.ts
  • If user was redirected from a protected page, returns them there after login

Current usage in this project

MainRoutes.tsx uses inline role checks (DashboardRoute, UserIndexElement) rather than wrapping all routes with AuthGuard. Additional protection layers:

Integrating guards

To wrap a layout with AuthGuard:
Login layout should wrap with GuestGuard similarly.