Refresh JWT Token Interceptor in Flutter

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024

ความคิดเห็น • 26

  • @emmalynnabiamos2412
    @emmalynnabiamos2412 2 ปีที่แล้ว

    Thanks for this!

  • @johndow618
    @johndow618 5 หลายเดือนก่อน

    Why don't you use the 'expiresIn' parameter to determine whether you need to refresh the JWT before making a request to the server?

  • @user-fo2jg2ln1n
    @user-fo2jg2ln1n 11 หลายเดือนก่อน

    THANK YOU

  • @matinrezaii3473
    @matinrezaii3473 2 ปีที่แล้ว

    Nice nice nice ! keep going

  • @fasilaj857
    @fasilaj857 ปีที่แล้ว +2

    Q: If you are using the existing headers for the _retry function, the accessToken you are using is the expired one right?

    • @ShakilAhmedPalatok
      @ShakilAhmedPalatok 10 หลายเดือนก่อน

      I had exactly the same problem, after hours of failed attempt I found the bug. The solution is to add the new accessToken with the header and retry with the updated header

  • @ntfnd4044
    @ntfnd4044 ปีที่แล้ว

    it is good practice to use the QueuedInterceptorsWrapper

    • @ronytesler
      @ronytesler ปีที่แล้ว

      But then you can't make calls in parallel, right?

  • @subinsuresh
    @subinsuresh 2 ปีที่แล้ว +2

    How to handle parallel api request with expired token?

    • @eggzzotic
      @eggzzotic 9 หลายเดือนก่อน

      I agree this is a challenge I am wrestling with ATM also.

  • @syfigaming4281
    @syfigaming4281 2 ปีที่แล้ว +2

    Please, implemention in project

  • @ulmasbekrakhmatullaev8808
    @ulmasbekrakhmatullaev8808 2 ปีที่แล้ว

    nice

  • @ThinKingKaraoke
    @ThinKingKaraoke ปีที่แล้ว

    How to use with GetX ?

  • @codingdesign8312
    @codingdesign8312 ปีที่แล้ว

    I refeshToken is Future and i call under onError function it auto many request , how i resoled , i use _retry function already

    • @ShakilAhmedPalatok
      @ShakilAhmedPalatok 10 หลายเดือนก่อน

      I had the exact same problem, your retry function is getting called with the same old access token, update your header with new access token and then retry using the updated header

    • @johndow618
      @johndow618 5 หลายเดือนก่อน +1

      To ensure that other requests wait until the token is refreshed (if necessary), you can use Completer. When the token update is complete, you'll call _completer.complete(), allowing other requests to properly send their request to the server with the updated token.

  • @conceptcoder
    @conceptcoder 2 ปีที่แล้ว

    Hi Gabriel McReynolds, I already likes and subscribe your channel. Can I asking more about this topic with you. I really need your help/ advice about refreshing token with dio. Where I can reach you to ask more ?
    Thanks.

  • @tranong142
    @tranong142 2 ปีที่แล้ว +1

    Nọ, this is not best practice, because u can not handle to call multiple api when unauthenticated,

    • @sojuz1204
      @sojuz1204 2 ปีที่แล้ว

      you mean handling multiple unauthenticated api calls at once?

    • @tranong142
      @tranong142 2 ปีที่แล้ว

      ​@@sojuz1204 yes, must have a mode for refresh token when the 1 refresh token is running.
      EG: At once loaded:
      request API 1 => unauthenticated => refresh token 1
      request 2 (async with request 1) => unauthenticated => wait refresh token 1 response => use new token recall request 2
      If i use your practice, request 2 will call new refresh token

    • @tranong142
      @tranong142 2 ปีที่แล้ว

      @chau cao Mình code web FE nên trong thời gian refreshing mình sẽ đặt 1 cờ,
      - Khi có unauthenticate mình sẽ check cái cờ đó trước, nếu có refreshing thì sẽ chờ request refreshing đó kết thúc và lấy luôn token mới của refreshing gọi lại api vừa unauthenticated

    • @louisesandrinee.1882
      @louisesandrinee.1882 ปีที่แล้ว +1

      i think it's better to use instance of dio. and to create a class to extends interceptor

    • @agungsubastian7384
      @agungsubastian7384 ปีที่แล้ว

      @@tranong142 is there any solution for this? I ran into this problem