Using it in your app
The reactive NestAuthController, a login-to-home widget example, and error handling.
NestAuthClient is enough on its own, but for a reactive UI wrap it in a NestAuthController — a ChangeNotifier that tracks auth state and notifies listeners on login and logout, so your widgets rebuild automatically.
The controller
Construct it with a client, then call restore() once on app start to load any persisted session:
State
| Getter | Type | Description |
|---|---|---|
status | AuthStatus | unknown, authenticated, or unauthenticated. |
user | SessionUser? | The signed-in user, or null. |
isAuthenticated | bool | Convenience for status == authenticated. |
isBusy | bool | True while a sign-in / sign-up / sign-out call is in flight. |
lastError | Object? | The error thrown by the most recent action (cleared when a new one starts). |
status starts as AuthStatus.unknown; after restore() it settles into authenticated or unauthenticated. Use the unknown state to show a splash / loading screen.
Methods
| Method | Description |
|---|---|
restore() | Load a persisted session on app start. |
signup({email, phone, password}) | Register, then load the user. |
login({providerName, credentials}) | Log in with a provider, then load the user. |
loginWithEmail(email, password) | Convenience email / password login. |
logout() | Clear the session and tokens. |
refreshUser() | Re-fetch the current user (e.g. after a profile update). |
The controller surfaces the common sign-in flows. For everything else — passwordless, social login, MFA, password reset, verification,
switchTenant— call the methods on the underlyingclient(auth.client.socialLogin(...)), thenawait auth.refreshUser()to update the UI.
A login-to-home root
Drive your whole tree off status with a ListenableBuilder:
A login screen just calls the controller — the tree updates itself when status flips to authenticated:
The home screen reads auth.user and signs out by calling auth.logout():
NestAuthController works with any state solution — pass it to provider, Riverpod, or just ListenableBuilder as above.
Error handling
Non-2xx responses throw NestAuthException, which mirrors the backend's error envelope:
Catch it to branch on code or statusCode:
When you use the controller, the same exception is stored on lastError (and still rethrown), so you can render it during a rebuild rather than catching it inline:
Models
The data types returned across the SDK: