Token Management

How the Flutter SDK manages your user’s tokens

s The Passage Flutter SDK manages your user's auth tokens for you. Anytime your user successfully registers or logs in, their auth token and refresh token (if applicable) are stored securely on their device or browser.

Token functions

Get auth token

You can access the current user's auth token this way:

final passage = PassageFlutter();
String? authToken = await passage.getAuthToken();

If the user has NOT authenticated or has been signed out, passage.tokenStore.getValidAuthToken() will return null.

Refresh auth token

If you've setup refresh tokens in your app (strongly recommended), you can call passage.tokenStore.refreshAuthToken() to get a new auth token. This method will store the new auth token and return it.

String newAuthToken = passage.tokenStore.refreshAuthToken();

Check if auth token is valid

You may want to check if your auth token is valid before using it to make sure you don't need to refresh the auth token.

// Retrieve auth token
String? authToken = await passage.tokenStore.getValidAuthToken();
 
// Check if the auth token is valid
bool isValid = await passage.tokenStore.isAuthTokenValid(authToken!);

Sign out user and remove tokens from device

When you call passage.currentUser.logout(), the user's tokens are removed from the device.

await passage.currentUser.logout();

Token storage

iOS

Your user's auth token and refresh token are both stored on device using Apple's Keychain API (opens in a new tab). When you sign out your user, the refresh token is revoked on the server and both tokens are removed from the device.

Android

Your user's auth token and refresh token are both stored on device using Android's own Encrypted Shared Preferences (opens in a new tab) library. When you sign out your user, the refresh token is revoked on the server and both tokens are removed from the device.

Web

Passage Flutter will store, lookup and clear auth tokens in localStorage (opens in a new tab) and in a cookie using a consistent key value.