-
Notifications
You must be signed in to change notification settings - Fork 47
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
Use of JWT callback to persist additional token info results in session being null. #33
Comments
I have somehow a similar issue @msardi23 . However, for me, it works when only adding the account.access_token in my token, however, adding both the access_token and the refresh_token gives me the same error as you, where the getSession() returns null. Not adding the refresh_token makes the getSession() return an existing session. This is my code that works, and I have commented out the line adding the refresh_token to the token object for reference.
For me, it seems that also adding a request token, maxes out the token size limit, or something. Because if I only add, for example: refreshToken: "refresh token", it works, and session is set. From what I can see, from the Astro.request and the request cookies, the authcookie is not set when adding the full refreshToken, but is set when only adding accessToken. The cookies remaining are: "authjs.csrf-token" and "authjs.callback-url" which for me, seems that something has happened when prosessing the extra data. The authjs cookie: "authjs.session-token" is missing. When removing refreshToken so the session is not null anymore, the request header looks correct with the "authjs.session-token" cookie now in place. I haven't calculated the size, but we might be hitting the browser cookie size limit (4kb). I know they have done something for this limitation for NextAuthJs: nextauthjs/next-auth#3579 (comment) Edit: Seemed to only work in dev. Built in prod or preview; session cookie is not set at all when doing changes in the callback as @msardi23 mentioned. |
I just tested this on the latest astro, @auth/core and auth-astro version without any issues. Do you still have this problem? |
I'm using my own version setting the refresh cookie in a separate cookie. However, I'll see if I can take a look at it and test! |
I am using the JWT callback to add additional information to the token like access_token, refresh_token and expires_at as outlined in the Auth.js docs here for the JWT callback and here for refresh token rotation.
While I have this working fine using Next.js 13 and Qwik, I have been struggling with Astro. As soon as I include logic in the JWT callback to enhance the token the session ends up being empty. When I remove the enhancement in the JWT callback the default session data is returned.
No errors are reported in the console. I am using the Azure AD provider.
If I then check session via .../api/auth/session it returns an empty object.
If I comment out
token.access_token = account.access_token;
in the JWT callback the default session data is returned.Same issue occurs using both JS and TS projects.
Please help 😀
The text was updated successfully, but these errors were encountered: