Closed niti-alzhemist closed 1 year ago
If I have 4 network requests and response is UNAUTHENTICATED, shouldRefresh will return true, all of requests will call refreshToken() ()to get the new OAuth2Token then retry the request.
Is it possible to call refreshToken only first time then retry all request?
Did you find the solution ?
Any update @felangel ??
I solved by using mutex (https://pub.dev/packages/mutex), locking the request when the first refresh job is called then release and inject new token when receive it @Star-Lord-76 @Stephen-Strange
I solved by using mutex (https://pub.dev/packages/mutex), locking the request when the first refresh job is called then release and inject new token when receive it @Star-Lord-76 @Stephen-Strange
Please attach example @niti-alzhemist
I solved by using mutex (https://pub.dev/packages/mutex), locking the request when the first refresh job is called then release and inject new token when receive it @Star-Lord-76 @Stephen-Strange
thank you
example
final m = Mutex();
AuthLink authLink = AuthLink(
getToken: () async {
print("lock");
await m.acquire();
final token = await getAccessToken();
m.release();
print("unlock");
debugPrint("Bearer ${token == null ? "is" : "is not"} Null");
if (token == null) return null;
return 'Bearer $token';
},
);
If I have 4 network requests and response is UNAUTHENTICATED, shouldRefresh will return true, all of requests will call refreshToken() ()to get the new OAuth2Token then retry the request.
Is it possible to call refreshToken only first time then retry all request?