New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(fresh_dio): replace Interceptor with QueuedInterceptor #68
Conversation
Hi @felangel do you have any estimates on reviewing this PR? |
sorry for the delay planning to test and publish today |
@vasilich6107 can you confirm whether the changes resolve the issue for you? |
You could test it by replacing
with
in your pubspec.yaml |
@felangel @vasilich6107 Is there anything else I can support? So that we can get on with the PR? |
I was waiting for confirmation that the changes in the PR address the issue. @SebastianKlaiber can you confirm? |
I'll check the related issue #29 and follow the steps to reproduce. |
Unfortunately, I could not find a way to clear all Queued Interceptors of a given type. Hopefully I have time to investigate a little more in this topic this week. Any suggestion from your side? |
@SebastianKlaiber thanks for help with testing |
I think we could solve the Issue if we add an JWT Decoder and check if the access token is a valid JWT and then check if the JWT is still valid. If the JWT is expired, then trigger the refresh callback. We could also add the validation function as a parameter, then the consumer of the library can specify when the access token is valid. Or we create an issue on the Dio repository. @felangel what is your opinion on this? |
@SebastianKlaiber @felangel Can we check if current token is same compared to token in request headers? In case current token is different then return it instead of calling refresh token. |
@Gaurav192 thanks for helping out. I was busy the last time, releasing a new version of my app. I will check your changes today. |
Just to make sure, are you using default values in repo and url: https://github.com/Gaurav192/fresh.git in pubspec? |
I checked out your repo and changed the version to the local path in the pubspec.yaml. I added a breakpoint and isEqual returns always true. |
Hi, |
I’ll try to take a look this weekend apologies for the delay |
@felangel if you have a suggestion, I'm happy to help further with the implementation, just currently not sure what direction the implementation should go in. Provide some validation logic or do some header checks. |
This can be picked up again after the dio 5.0.0 merge. |
@SebastianKlaiber just resolved merge conflicts and pulled in dio 5.0.0 can you please re-test when you have a chance? Thanks! |
Thanks. Hopefully I've some time this afternoon. |
Still the same issue with the cookie example, https://github.com/artflutter/fresh_repro. I did some more investigation: final response = await authRestClient.refreshToken(refreshToken: refreshToken);
return OAuth2Token(
accessToken: response.token,
refreshToken: response.refreshToken,
); But If I add some delay, then I get too much refresh calls. return await Future.delayed(const Duration(milliseconds: 500), () async {
final response = await authRestClient.refreshToken(refreshToken: refreshToken);
return OAuth2Token(
accessToken: response.token,
refreshToken: response.refreshToken,
);
}); The new version is using a shelf API with bearer auth from this repository. https://github.com/graphicbeacon/dart_spa_boilerplate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ✅
Interceptors are called concurrently, this could lead to a problem if multiple API calls are executed at the same time. Therefore, Queued Interceptor was introduced to solve this problem.
I also updated dio to version 4.0.6 because Queued Interceptor was introduced in version 4.0.2
From the Dio documentation: