onRequest method

  1. @override
void onRequest(
  1. RequestOptions options,
  2. RequestInterceptorHandler handler
)
override

Called before a request is sent.

Implementation

@override
void onRequest(RequestOptions options, handler) {
  if (isPreemptivelyRefreshBeforeExpiry &&
      !authOptions.ignoreAuthForPaths.contains(options.path)) {
    try {
      final isExpired = JwtDecoder.isExpired(authHandler.jwt ?? '');

      if (isExpired) {
        authHandler.refreshTokenCallback(options, handler);
      } else {
        handler.next(options);
      }
    } catch (e) {
      debugPrint(e.toString());
    }
  } else {
    handler.next(options);
  }
}