clean_framework icon indicating copy to clipboard operation
clean_framework copied to clipboard

[Auth-Graphql] How to re-request an operation with new headers (refresh token)?

Open iamnabink opened this issue 2 years ago • 0 comments

Hi, I am trying to use your package to build an personal project (GraphQL) and finding hard to implement a refresh process. Using Dio I could block the client so all the subsequence requests goes to a queue (using Queuedinterceptor), refresh and then queue is processed. Using your package, do I need to implement something like that by myself? Right now I am using AuthLink which is in your case passing by custom class GraphQLToken :

GraphQLToken(builder: () async {
       final token = await getAccessToken();
       return `Bearer $token`
    },
  );

Unfortunately currently for the workaround, I have updated the API to return an expires_at time stamp. So, I can check to see if the token is expired before setting the header. If it is, then refresh the token, attach it, and then make the request.

It's not ideal, since tokens can expire for other reasons (like token expiring at the time of request and response is 401), so a true solution using the stream would definitely be preferable. Thanks in advance.

iamnabink avatar Feb 22 '24 07:02 iamnabink