JWT token not being updated, but is passing correct data to the session #11772
Replies: 1 comment
-
I believe this to be because server components cannot modify the token. I have opened another thread for that issue |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using Auth.js V5 with the credentials provider. I am sending an authtication request to my Django REST Framework backend, where it authenticates the user, and returns the user information, along with a refresh and access token. The refresh token expiry is 1 day, and the access token is set to expire in 1 minute.
I am trying to decode the accessToken in the JWT section, and check to see if the token has expired or not. If it has, I am sending a request to the backend to refresh the accessToken using the refreshToken.
I am expierencing two errors. One issue is that the auth.ts file seems to be initilising twice, once where the token.accessToken is undefined, which causes a format issue on the backend, which I handle by not updating the accessToken and console.logging the error. Below is the log from my BE server showing this
The other issue is that when the refresh token is correctly used to retrieve the new accessToken, and I handle the updated in the return statement here:
the new access token is successfully passed to the session, and I can see the accessToken had updated (see below), however, when I refresh the page it seems like this new accessToken is never saved to the authjs.session-token saved in the cookies.
Below is the console.log showing that the new accessToken is being passed to the session.
But, when I refresh the page I would expect to see the new JWT token printed out, but you can see it is still showing the original accessToken that is passed back on SignIn
This means everytime I refresh the page a new accessToken is retrieved, and then put into the session, as it is always checking the expiry of the old accessToken that never gets updated.
Why is the new accessToken not saving to the authjs.session-token in my cookies, and why am I always getting two requests to my BE to refresh the token where, for the first one, the refreshToken is undefined first?
I have added any relevant files below:
Beta Was this translation helpful? Give feedback.
All reactions