TokenStorageService class
Token storage adapter for the Fresh Dio automatic token refresh system.
Implements the TokenStorage interface from the fresh_dio package,
bridging Fresh Dio's token refresh mechanism with SecureStorage.
This service enables automatic access token refresh by reading stored tokens on initialisation, writing new tokens after successful refreshes, and deleting tokens on logout or refresh failure.
Example setup:
final fresh = Fresh<AuthTokenModel>(
tokenStorage: TokenStorageService(),
refreshToken: (token, client) async {
return newToken;
},
);
final dio = Dio()..interceptors.add(fresh);
See also:
- SecureStorage for the underlying encrypted storage.
- AuthTokenModel for the token data structure.
- Implemented types
Constructors
- TokenStorageService()
-
Creates a token storage service instance.
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
delete(
) → Future< void> -
Removes authentication tokens from secure storage.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
) → Future< AuthTokenModel?> -
Retrieves the stored authentication tokens from secure storage.
override
-
toString(
) → String -
A string representation of this object.
inherited
-
write(
AuthTokenModel token) → Future< void> -
Persists authentication tokens to secure storage.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited