TokenStore class
A utility class to store, retrieve, manipulate and check Userfront JWTs.
Properties
- accessToken ↔ String?
-
The access token. Use this when calling Userfront API endpoints.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- idToken ↔ String?
-
The ID token, containing information about the user.
getter/setter pair
- localStorage ↔ SharedPreferences
-
A
SharedPreferencesinterface, allowing platform-agnostic storage and retrieval of key-value pairs.getter/setter pair - refreshToken ↔ String?
-
The refresh token. Use this to call the Userfront API /auth/refresh
method when the access token is expired.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- tenantId → String
-
The Userfront account-level tenant ID, set via
Userfront.init in normal usage.
final
-
tokens
→ Map<
String, String?> -
A map containing all three tokens: accessToken, idToken
and refreshToken. Note that if a token is absent,
it may be null OR the empty string ''
no setter
Methods
-
clearTokens(
) → dynamic - Clears the accessToken, idToken and refreshToken from the device, by setting them all to the empty string ''.
-
isAccessTokenLocallyValid(
) → dynamic - Checks whether the accessToken is locally valid i.e. it exists and is not expired.
-
isAnyTokenLocallyValid(
) → dynamic - Checks whether either the accessToken or refreshToken is locally valid, i.e. exists and is not expired.
-
isRefreshTokenLocallyValid(
) → dynamic - Checks whether the refreshToken is locally valid i.e. it exists and is not expired.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
readTokens(
) → dynamic - Reads the tokens from the device. This ALWAYS overwrites the instance's accessToken, idToken and refreshToken, even if the local device does not have them set.
-
shouldRefresh(
) → dynamic - Checks whether we should refresh the accessToken: the accessToken is not locally valid, but we do have a locally valid refreshToken.
-
toString(
) → String -
A string representation of this object.
inherited
-
writeTokens(
{String? accessToken, String? idToken, String? refreshToken}) → dynamic - Writes the three provided tokens to the device.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
create(
dynamic tenantId, [dynamic getInstance = SharedPreferences.getInstance]) → Future< TokenStore> - Creates and initializes a new TokenStore instance.