JwtHeroInterceptor class
Intercepts HTTP requests to handle JWT token management.
This interceptor is responsible for adding JWT tokens to request headers, refreshing expired tokens, and retrying requests with new tokens if needed. It uses the provided token storage to load and validate tokens, and the session manager to handle session expiration.
The interceptor also initializes separate clients for refreshing tokens and retrying requests.
Mixins:
JwtRefresherMixin: Provides functionality to refresh JWT tokens.RequestRetryMixin: Provides functionality to retry requests.
Constructors
- JwtHeroInterceptor({TokenStorage tokenStorage = const SecureTokenStorage(FlutterSecureStorage()), required Dio baseClient, required Refresh onRefresh, required SessionManager sessionManager})
- Intercepts HTTP requests to handle JWT token management.
Properties
- baseClient → Dio
-
The base client to make requests.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- onRefresh → Refresh
-
The function to refresh the JWT token.
final
- refreshClient ↔ Dio
-
The client to make requests to refresh the JWT token.
latefinal
- retryClient ↔ Dio
-
The client to retry the request after refreshing the JWT token.
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sessionManager → SessionManager
-
The session manager to expire the session.
final
- tokenStorage → TokenStorage
-
The storage to load and save the JWT token.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onError(
DioException err, ErrorInterceptorHandler handler) → Future< void> - Called when an exception was occurred during the request.
-
onRequest(
RequestOptions options, RequestInterceptorHandler handler) → Future< void> - Called when the request is about to be sent.
-
onResponse(
Response response, ResponseInterceptorHandler handler) → void -
Called when the response is about to be resolved.
inherited
-
refresh(
{required RequestOptions options, JwtToken? currentJwtToken, required Dio refreshClient, required TokenStorage tokenStorage, required Refresh onRefresh}) → Future< JwtToken> -
Refreshes the JWT token using the provided
onRefreshfunction.inherited -
retry(
{required Dio retryClient, required RequestOptions requestOptions, required Future< Map< buildHeaders()}) → Future<String, String> >Response< Response> > -
Retries the request with the new JWT token.
inherited
-
shouldRefresh<
R> (Response< R> ? response) → bool - Checks if the response should be refreshed.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited