AuthInterceptor class
Attaches credentials to requests and recovers from rejected tokens.
Concurrent rejections share a single refresh: the first request to see a
401 performs the refresh, and every other waits on the same future, then
retries. NetGuard 1.x instead maintained a hand-rolled pending queue that
cast a ResponseInterceptorHandler to ErrorInterceptorHandler — sibling
types, so that path always threw.
- Inheritance
-
- Object
- Interceptor
- AuthInterceptor
Constructors
- AuthInterceptor({required AuthCallbacks callbacks, AuthConfig config = const AuthConfig(), Dio? retryClient})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isRefreshing → bool
-
Whether a refresh is currently running.
no setter
- lastLogoutTime → DateTime?
-
When logout last fired.
no setter
- lastRefreshResult → RefreshResult?
-
The most recent refresh outcome.
no setter
- lastRefreshTime → DateTime?
-
When a refresh was last attempted.
no setter
- logoutCooldownRemaining → Duration?
-
Time left on the logout cooldown, or
nullwhen not throttled.no setter - queuedRequestsCount → int
-
Always zero; retained for source compatibility. Concurrent requests now
await a shared refresh future rather than sitting in a queue.
no setter
- refreshTokenCooldownRemaining → Duration?
-
Time left on the refresh cooldown, or
nullwhen not throttled.no setter - retryClient ← Dio
-
The client used to replay a request after refresh.
no getter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clear(
) → void - Drop all transient auth state.
-
forceLogout(
) → Future< void> - Sign out immediately, bypassing the cooldown.
-
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.
override
-
onRequest(
RequestOptions options, RequestInterceptorHandler handler) → Future< void> -
Called when the request is about to be sent.
override
-
onResponse(
Response response, ResponseInterceptorHandler handler) → Future< void> -
Called when the response is about to be resolved.
override
-
refreshNow(
) → Future< String?> - Trigger a refresh outside the request path, for diagnostics.
-
resetLogoutCooldown(
) → void - Reset the logout throttle.
-
resetRefreshTokenCooldown(
) → void - Reset the refresh throttle and drop any cached outcome.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- attemptKey → const String
- Counts auth retries so a persistently rejecting endpoint terminates.
- loginKey → const String
- Marks a login request, which must not be retried on 401.
- replayKey → const String
- Marks a request that already carries a freshly refreshed token.
- skipRefreshKey → const String
- Marks a request that must never trigger recursive refresh.