You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, when we authenticate into Kinetic, we store the access and the refresh tokens in the local storage. The access token has a short lifespan, to be precise, an hour. When the access token expires the user is logged out.
We should intercept each authenticated request and check if the access token has expired. If so we should then use the refresh token to renew the access token and the request for the resources should continue as expected.
AccountsJs provides an implementation of this mechanism for Apollo Client but as we are using React Query for managing the queries and mutations we should implement our own interception handler.
Currently, when we authenticate into Kinetic, we store the access and the refresh tokens in the local storage. The access token has a short lifespan, to be precise, an hour. When the access token expires the user is logged out.
We should intercept each authenticated request and check if the access token has expired. If so we should then use the refresh token to renew the access token and the request for the resources should continue as expected.
AccountsJs provides an implementation of this mechanism for Apollo Client but as we are using React Query for managing the queries and mutations we should implement our own interception handler.
We can leverage
graphql-request
's middleware feature to achieve that:https://github.com/prisma-labs/graphql-request#middleware
An example of how AccountJs had implemented the interception of every mutation:
https://github.com/accounts-js/accounts/blob/ff983b8f9603f6295f2b7c9830a7926bc36e81c4/packages/graphql-client/src/graphql-client.ts#L215
They are checking if we have a valid token. If not try to refresh it, provided the mutation is not RefreshToken itself.
The text was updated successfully, but these errors were encountered: