TokenKeeperInterceptor constructor

TokenKeeperInterceptor({
  1. required TokenKeeper keeper,
  2. required Dio dio,
  3. String headerName = 'Authorization',
  4. String scheme = 'Bearer',
  5. bool shouldRefreshOn(
    1. Response? response
    )?,
  6. void onRefreshFailed(
    1. Failure failure
    )?,
})

Creates an interceptor.

  • keeper is the source of tokens.
  • dio is used to retry the original request after a refresh. Pass the same Dio instance the interceptor is attached to.
  • headerName / scheme customise the auth header (defaults produce Authorization: Bearer <token>).
  • shouldRefreshOn lets you treat additional status codes (e.g. 419) as auth failures.
  • onRefreshFailed is invoked when a 401-triggered refresh fails. Use it to navigate directly to login from the interceptor layer.

Implementation

TokenKeeperInterceptor({
  required this.keeper,
  required this.dio,
  this.headerName = 'Authorization',
  this.scheme = 'Bearer',
  bool Function(Response<dynamic>? response)? shouldRefreshOn,
  this.onRefreshFailed,
}) : _shouldRefreshOn = shouldRefreshOn ?? _defaultShouldRefreshOn;