Skip to main content
By the end of this guide you will have AilitaProvider wrapping your app, AuthGuard protecting a route, LoginForm handling authentication, and useAuth displaying the current user.

What you’ll build

  • providers.tsx — AilitaProvider wrapper with tenant config
  • (protected)/layout.tsx or ProtectedRoute.tsx — AuthGuard route protection
  • login/page.tsx or LoginPage.tsx — Login page with LoginForm
  • dashboard/page.tsx or DashboardPage.tsx — Protected page using useAuth

1

Install and configure

See Installation for full setup details including Tailwind CSS.
2

Create the Providers wrapper

Always include onSessionExpired. Without it, expired sessions silently break the app — users get stuck with no feedback and no path back to login.
3

Wrap your root layout

4

Protect a route with AuthGuard

Always include loadingFallback. Omitting it causes a redirect flash for every authenticated user on each page load during the ~200–500ms silent token refresh on mount.
5

Add a login page with LoginForm

LoginForm handles all login states internally: password submission, OTP challenges, TOTP verification, and TOTP setup on first admin login. No additional wiring required for the basic case.
6

Read the current user in a protected page

user is null on initial render while the silent refresh runs. AuthGuard ensures this page only renders when isAuthenticated is true, so by the time this component mounts, user will be populated.

Next steps

AilitaProvider props

Full prop reference for clientId, baseUrl, onSessionExpired, and more.

AuthGuard patterns

Role-based access, loadingFallback, and the UX-gate security model.