BearerStrategy class

Reads the JWT access token from memory (fast) with a Hive fallback (persistent). Attaches it as Authorization: Bearer <token>.

The app creator saves the token after login:

await BearerStrategy.saveToken(token);
Inheritance

Constructors

BearerStrategy({required String tokenKey})

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tokenKey String
Hive box key used to persist the token. Must match the key used when saving after login. e.g. 'access_token'
final

Methods

apply(RequestOptions options) Future<void>
Attach auth credentials to options before the request is sent.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onUnauthorized() Future<void>
Called when the API layer receives a 401. Use to trigger token refresh or logout in your app provider.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

clearToken({required String key}) Future<void>
Clear the token from memory and Hive. Call this on logout.
saveToken(String token, {required String key}) Future<void>
Persist and cache the token. Call this after a successful login.