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

Implement refresh access token logic #733

Merged
merged 3 commits into from
Dec 14, 2023
Merged

Conversation

dmtrek14
Copy link
Collaborator

Add refresh token logic

  • Add function to the auth route to check the expiry of the token and attempt a refresh against the OIDC provider endpoint
  • Add necessary fields to next-auth types

Copy link
Contributor

@negreirosleo negreirosleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's working for me 👍

dmtrek14 and others added 3 commits December 14, 2023 10:40
Add refresh token logic

- Add function to the auth route to check the expiry of the token and attempt a refresh against the OIDC provider endpoint
- Add necessary fields to next-auth types
The jwt callback is called when the session is created or updated, this
change makes the token refresh happen when the session is updated and
it fixes the accessTokenExpires logic.
The RefreshSession HOC adds 2 pieces of logic to the components:

1. it refreshes the session each 5 minutes, so if a token is expired
it will try to refresh after 5minutes.
2. it checks if the token is expired on the window focus, and if it is
expired it will try to refresh the token.

This component is basically a wrapper for those funcionalities and
it was made as a HOC instead of a hooks because it needed to be used
within `providers.tsx` but it needed to be under `SessionProvider` since
it uses the `useSession` hook.
@dmtrek14 dmtrek14 merged commit 2e6c68f into main Dec 14, 2023
2 checks passed
@dmtrek14 dmtrek14 deleted the add-refresh-token-logic branch December 14, 2023 18:46
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

Successfully merging this pull request may close these issues.

3 participants