Basic usage
PlaceAuthGuard around any route or section that requires authentication. The fallback
prop is rendered when the user is not authenticated; loadingFallback is rendered while
auth state is being restored.
Props
Rendered when the user is not authenticated or lacks required roles. Typically a redirect
component (
<Navigate to="/login" /> in React Router) or a useEffect-based redirect
(Next.js App Router).Rendered while authentication state is being restored (silent token refresh on mount).
Always provide this — the ~200-500ms refresh window causes a redirect flash without it.
Optional list of role names the user must have. Uses AND logic — all listed roles must be
present. Role strings come from the backend. There is no client-side enum.
Role-protected routes
requiredRoles uses AND logic — all listed roles must be present.
A user with ['ADMIN'] will NOT pass requiredRoles={['ADMIN', 'SUPER_ADMIN']}.How AuthGuard evaluates state
AuthGuard checks three conditions in order, matching the source code logic:- If
isLoadingistrue— rendersloadingFallback - If
isAuthenticatedisfalse— rendersfallback - If
requiredRolesis set and user does not have ALL listed roles — rendersfallback - Otherwise — renders
children
What AuthGuard does not do
- Does not make any network requests
- Does not verify tokens (that is AuthProvider’s responsibility via silent refresh)
- Does not integrate with the server — it is purely client-side React rendering logic
Next steps
Quickstart
See a complete end-to-end integration example with AilitaProvider, AuthGuard, and LoginForm.

