Quick setup
Wrap your app (or its authenticated subtree) withAilitaProvider. It handles tenant
discovery, theme injection, and token refresh automatically.
Props
Merchant subdomain slug (e.g.
"sanfernando"). Used in GET /auth/discovery?slug= on mount.
Changing this prop re-runs discovery.Application identifier (e.g.
"colegios"). Passed as a useEffect dependency alongside
slug and baseUrl — changing any of these three re-runs discovery.Base URL of the API, e.g.
https://api.yourdomain.com/api/v1. Set once before discovery
runs. All subsequent API calls use this base URL.Called when the refresh token is invalid and tokens are cleared. Redirect to
/login here.
Treat as required — without it, users silently lose their session with no recovery path.
The 401 refresh queue in client.ts fires this callback after a failed refresh attempt.Rendered while discovery is in progress. Defaults to
null (blank screen). Provide a
spinner or skeleton to avoid a content flash on mount.Rendered if discovery fails (network error, unknown slug). Defaults to
null. Provide
an error state that prompts the user to refresh or contact support.How discovery works
On mount,AilitaProvider runs the following sequence:
- Sets the Axios base URL to your
baseUrlprop - Calls
GET /auth/discovery?slug={slug}to fetch tenant configuration - Receives tenant data: name, colors,
loginMode,signupMode,publicApiKey - Injects
X-App-IDandX-Mid-Keyheaders into all subsequent API requests via an Axios interceptor
The
appId prop is used as a useEffect dependency to re-run discovery if it changes.
The actual X-App-ID header value sent to the backend comes from data.app in the discovery
response — not from the prop directly. If your slug is correct, this is transparent.
It only matters if you inspect network traffic and see a different value than your prop.Internal composition
AilitaProvider composes three layers internally. Consumers never need to instantiate
ThemeProvider or AuthProvider directly.
loginMode and signupMode
Your tenant’sloginMode and signupMode are returned by the discovery endpoint and
control which UI flows LoginForm and SignupForm render.
loginMode
| Value | Behavior |
|---|---|
PASSWORD | Standard email + password login |
OTP_EMAIL | Login via one-time code sent to email (no password) |
PASSWORD_OR_OTP_EMAIL | User chooses between password or email OTP |
signupMode
| Value | Behavior |
|---|---|
OPEN | Anyone can register |
INVITATION_ONLY | Registration requires an invitation link |
These values are returned by the discovery endpoint and set automatically. Your tenant’s
loginMode and signupMode are configured in the ailita backend admin panel — you do not
need to pass them as props.Next steps
Protect routes with AuthGuard
Require authentication or specific roles before rendering protected UI.

