onRequest method
Intercepts and modifies outgoing requests.
Adds the Authorization header with the Bearer token to every request.
options: The request options containing the request details.handler: The interceptor handler to continue or reject the request.
Implementation
@override
Future onRequest(
RequestOptions options,
RequestInterceptorHandler handler,
) async {
try {
// Add the Authorization header with the Bearer token.
options.headers['Authorization'] = "Bearer $publicKey";
} catch (e) {
// Log any exceptions that occur during request modification.
log('AuthorizationInterceptor caught an error: $e');
}
// Continue the request.
return handler.next(options);
}