Getting Started
Install the SDK, configure the backend, create a client, and pick a token store.
Install
Add the package to your pubspec.yaml:
Then fetch it:
SecureTokenStorage depends on flutter_secure_storage, which is pulled in transitively. On iOS no extra setup is needed; on Android make sure your minSdkVersion is at least 18.
Backend setup
Mobile clients don't use cookies, so the backend must return tokens in the response body. Run your nest-auth backend in header token mode:
Without
accessTokenType: 'header'the server sets a session cookie instead of returningaccessToken/refreshTokenin the body, and the SDK has nothing to persist.
Create a client
NestAuthClient is the entry point. Only baseUrl is required:
The constructor signature is:
A trailing slash on baseUrl is trimmed for you, so https://api.example.com and https://api.example.com/ behave identically.
Two top-level getters report the current auth state, and close() releases the underlying HTTP client when you're done with it:
If you pass your own
http.Client, you are responsible for closing it.NestAuthClient.close()closes whatever client it holds — the one you passed, or the one it created.
Token storage
The client persists the access and refresh tokens through a TokenStorage. Pick the adapter that fits your environment:
SecureTokenStorage— backed byflutter_secure_storage(platform keychain / keystore). Recommended for production.InMemoryTokenStorage— ephemeral; tokens live only for the lifetime of the process. The default, and handy for tests.
SecureTokenStorage namespaces its keys with a prefix (default nest_auth.) and can wrap a pre-configured FlutterSecureStorage instance:
Custom storage
Implement TokenStorage to back the client with anything else — an encrypted database, a platform channel, etc. It is a three-method key / value interface:
The client reads and writes two keys — accessToken and refreshToken.
Next steps
- Authentication — sign users in and out, reset and change passwords, verify email & phone.
- Using it in your app — wire the client into a reactive Flutter UI.