Token Management
How the React Native SDK manages your user’s tokens
The Passage React Native 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.
Token functions
Get auth token
You can access the current user's auth token this way:
const authToken = await passage.getAuthToken();
If the user has NOT authenticated or has been signed out, Passage.getAuthToken()
will return null
.
Refresh auth token
If you've setup refresh tokens in your app (strongly recommended), you can call Passage.refreshAuthToken()
to get a new auth token. This method will store the new auth token and return it.
const newAuthToken = passage.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
const authToken = await passage.getAuthToken();
// Check if the auth token is valid
const isValid = await passage.isAuthTokenValid(authToken);
Sign out user and remove tokens from device
When you call Passage.signout()
, the user's tokens are removed from the device.
await passage.signOut();
Token storage
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.
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.