Wiring Guide
Recipes for the three things every Khata front-end does: mount the provider, gate on the session, and edit the profile. All of these are presentational — swap in your own router or layout as needed.
📦 1. Mount the provider
AuthProvider must wrap any component that calls useAuth.
📦 2. Gate on the session
Automatic redirect
AuthPage calls onBack on its own once currentUser becomes truthy, so
it works as a route guard without a useEffect. mode is fully
controlled, so the login/register toggle never unmounts the form.
📦 3. Profile screens
ProfileCreate, ProfileEdit and ProfileView render the profile UI and
delegate persistence to callbacks you supply — the library does not know how
your backend stores profiles.
The three screens take flat props, not a user object:
| Component | Props |
|---|---|
ProfileView |
name, username, email, onEdit?, loading? |
ProfileEdit |
name, username, email, onSubmit, onBack?, loading?, error? |
ProfileCreate |
onSubmit, defaultUsername?, defaultEmail?, onBack?, loading?, error? |
onSubmit always receives { name, email } — persistence is yours.
Client-side validation only
AuthPage validates username >= 3 and password >= 6 before calling
your callback. The auth server remains the authority — never skip its
validation.
📦 4. Authenticated API calls
Use createApiClient for any backend that shares the auth-server login. A
plain axios instance is fine for unauthenticated endpoints.
For an existing client, attachAuthInterceptors(client) decorates it in
place with the same request/response behaviour.
🔗 Related
- 01 – Overview
- Auth Server contract:
docs://specon thestandardsMCP