Skip to content
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

Kinetic should automatically refresh the access token when expired #165

Open
tedraykov opened this issue Jan 9, 2023 · 0 comments
Open
Assignees

Comments

@tedraykov
Copy link
Collaborator

tedraykov commented Jan 9, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants