Skip to content

Refresh token within interceptor #58

Answered by agordn52
voytech-net asked this question in Q&A

You must be logged in to vote

Hi @voytech-net,

Under the hood, Nylo uses Dio.
You can try this.

class ExampleInterceptor extends Interceptor {
  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    return super.onRequest(options, handler);
  }

  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) {
    handler.next(response);
  }

  @override
  void onError(DioException dioException, ErrorInterceptorHandler handler) async {
    if (dioException.response?.statusCode == 401) {
      // If a 401 response is received, refresh the access token
      String newAccessToken = await ApiService().refreshToken();

      // Update the request header with the n…

Replies: 1 comment

You must be logged in to vote
0 replies
Answer selected by voytech-net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants