-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
How to update the session after refresh JWT token? #1357
Comments
What about using getToken() instead of getSession()? import { getToken } from 'next-auth/jwt';
import axios from 'axios';
export default async (req, res) => {
const token = await getToken({ req, secret: process.env.JWT_SECRET });
if (!token) {
return res.status(401).json({ status: 401, message: 'Unauthorized' });
}
let accessToken = token.accessToken;
if (Date.now() >= token.accessTokenExpires) {
const refreshToken = await refreshAccessToken(token);
accessToken = refreshToken.accessToken;
}
const response = await axios.post(
'<url>',
formData,
{
headers: {
Accept: "application/json",
Authorization: `Bearer ${accessToken}`,
},
},
);
res.status(200).json({data: response.data});
}; |
@ramiel Did you eventually get past this issue? I was running into the same thing |
Hi there! It looks like this issue hasn't had any activity for a while. It will be closed if no further activity occurs. If you think your issue is still relevant, feel free to comment on it to keep it open. (Read more at #912) Thanks! |
Hi there! It looks like this issue hasn't had any activity for a while. To keep things tidy, I am going to close this issue for now. If you think your issue is still relevant, just leave a comment and I will reopen it. (Read more at #912) Thanks! |
Hi there!
Your question
How to update
next-auth.session-token
cookie from server side?What are you trying to do
I'm implementing the refresh token for custom provider.
So, I have next-auth options as below:
Also I have an API endpoint where I try to get the session via helper
getSession({req})
.So, it works fine until need to refresh token.
My example:
/api/send-from
- there I can get the refreshed token from the sessionjwt
callback - thetoken
will old one (not refreshed previous) from cookiesession
fromgetSession()
will be with old access token (refreshed token is lost)If user switches between any tabs and returns to the form page it runs the
/api/auth/session
and updates the cookies.Does anybody know how to update the cookie correctly?
The text was updated successfully, but these errors were encountered: