TokenStorage class
Persistent, secure storage for the session's TokenPair, shared by every GraphQLClient in the app through the i singleton.
Tokens (and their timestamps) live in the platform keychain/keystore via
flutter_secure_storage; a shared_preferences flag backs
clearOnInstall. GraphQLClient reads and writes it on its own when
refreshCallback is configured — the app only touches it directly to log
in (saveToken), log out (deleteToken) or observe the session
(setTokenListener, getToken).
Which write notifies listeners
| Call | Use it for | Listeners |
|---|---|---|
| saveToken | login / a brand-new session | called with the access token |
| updateToken | a token refresh | not called (silent) |
| deleteToken | logout / revoke | called with null |
The split exists so a refresh doesn't look like an auth-state change to an app that rebuilds routing from setTokenListener.
Properties
-
accessToken
→ Future<
String?> -
The stored access token, or
nullwhen logged out. Read on every request, so a token written by updateToken is picked up immediately.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
-
refreshToken
→ Future<
String?> -
The stored refresh token, or
nullwhen logged out or when the session has none.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clearOnInstall(
) → void - Wipes stored credentials on the first launch after a (re)install.
-
deleteToken(
) → Future< void> -
Clears the stored session and notifies token listeners with
null. -
getToken(
) → Future< TokenPair?> -
Reads the stored session, or
nullwhen there is no (non-empty) access token — i.e. nobody is logged in. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeTokenListener(
) → void - Removes every listener registered with setTokenListener.
-
saveToken(
TokenPair pair) → Future< void> - Persists a freshly issued session (e.g. on login) and notifies token listeners. Timestamps default to now.
-
setTokenListener(
void listener(String?)) → void -
Registers
listenerto be called with the new access token when a session is saved via saveToken, and withnullwhen it is cleared via deleteToken. Not called on a silent refresh (updateToken). -
toString(
) → String -
A string representation of this object.
inherited
-
updateToken(
TokenPair pair) → Future< void> -
Silently persists a refreshed
pair— token listeners are NOT notified, so an app reacting to them (e.g. rebuilding routing) isn't disturbed by a refresh. The next request simply reads the new tokens from storage.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- i → TokenStorage
-
The app-wide instance. All GraphQLClients use this one.
no setter