onRequest method

  1. @override
Future onRequest(
  1. RequestOptions options,
  2. RequestInterceptorHandler handle
)

Add Bearer token to Authorization Header

Implementation

@override
Future onRequest(
    RequestOptions options, RequestInterceptorHandler handle) async {
  final token = await oauth.fetchOrRefreshAccessToken().catchError((err) {
    if (onInvalid != null) {
      onInvalid!(err);
    }
    return null;
  });

  if (token != null) {
    options.headers.addAll({"Authorization": "Bearer ${token.accessToken}"});
  }

  return handle.next(options);
}