Closed tokogame closed 10 months ago
We could not detect a valid reproduction link. Make sure to follow the bug report template carefully.
To be able to investigate, we need access to a reproduction to identify what triggered the issue. We need a link to a public GitHub repository. Example: (NextAuth.js example repository).
The bug template that you filled out has a section called "Reproduction URL", which is where you should provide the link to the reproduction.
Depending on the reason the issue was closed, you can do the following:
In general, assume that we should not go through a lengthy onboarding process at your company code only to be able to verify an issue.
In most cases, a private repo will not be a sufficient minimal reproduction, as this codebase might contain a lot of unrelated parts that would make our investigation take longer. Please do not make it public. Instead, create a new repository using the templates above, adding the relevant code to reproduce the issue. Common things to look out for:
Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps by opening a new issue.
We look into every issue and monitor open issues for new comments.
However, sometimes we might miss a few due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.
Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.
Environment
localhost → node --version v18.17.0
Apple M1 Pro Ventura 13.3.1
Chrome Version 119.0.6045.105 (Official Build) (arm64)
Vercel Node 18.x
Reproduction URL
https://nextauth-session-issue-6j9zk410s-tokogames-projects.vercel.app/
Describe the issue
On localhost, Google login always works perfectly fine. But upon deploying this to Vercel, session is always empty {} after successful Google login. I looked at the logs on Vercel and I can see that session callback was never executed on Vercel (only executed on localhost)
package.json: `"dependencies": { "axios": "^0.21.1", "bootstrap": "^5.2.1", "next": "^14.0.1", "next-auth": "4.24.4", "next-pwa": "^5.4.4",
},`
[...nextauth].js:
export const authOptions = { providers: [ GoogleProvider({ clientId: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, }), ], secret: process.env.NEXTAUTH_SECRET, jwt: { secret: process.env.NEXTAUTH_SECRET, encryption: true, }, debug: true, session: { // Choose how you want to save the user session. // The default is
"jwt", an encrypted JWT (JWE) stored in the session cookie. // If you use an
adapterhowever, we default it to
"database"instead. // You can still force a JWT session by explicitly defining
"jwt". // When using
"database", the session cookie will only contain a
sessionToken` value, // which is used to look up the session in the database. strategy: "jwt",},
callbacks: { async jwt({ token, user, account }) { // Persist the user.authToken from signIn callback to the token.authToken
}, };`
My component that uses session:
LoginBtn.js `function LoginBtn({ provider }) { const { data: session, status } = useSession(); const [loggedIn, setLoggedIn] = useState(null);
let loginButton = (
<OptimizedImage onClick={() => signIn("google", { callbackUrl: "/members/profile" })} priority={true} src="/assets/google-login.png" alt={"Login with Google"} height={32} width={82} />
);
let profileButton = (
<Link prefetch={false} href={"/members/profile"} legacyBehavior> <OptimizedImage priority={true} src={session?.profilePictureUrl} alt={session?.emailAddress + " profile image"} height={25} width={25} />
);
useEffect(() => { if (session == null && status === "loading") { return; } else if (session == null && status === "unauthenticated") { setLoggedIn(false); return; } else if (session != null && status === "authenticated") { setLoggedIn(true); return; } }, [session, status]);
return loggedIn == null ? null : loggedIn ? profileButton : loginButton; }
export default LoginBtn;`
From Vercel's log: i can see these 2 logs were printed:
nextauth.js jwt reqGoogleTokenSignIn: Received response from be. authToken: Lcoury0Lfl5MRHfRVs6GY280H144=
nextauth.js jwt: setting token's userId and authToken
but it's missing the log from session callback ("nextauth.js session: setting session's userId and authToken") and there was no error. This log was always printed if i run it on localhost.
Please tell me what can be different between localhost and Vercel deployment such that the session callback can be skipped?
How to reproduce
Open https://nextauth-session-issue-6j9zk410s-tokogames-projects.vercel.app and hit google login button on the top right. There should be no error but https://nextauth-session-issue-6j9zk410s-tokogames-projects.vercel.app/api/auth/session always shows empty {}
Expected behavior
Open https://nextauth-session-issue-6j9zk410s-tokogames-projects.vercel.app and hit google login button on the top right. On successful login, you should be redirected to https://nextauth-session-issue-6j9zk410s-tokogames-projects.vercel.app/members/profile
and
https://nextauth-session-issue-6j9zk410s-tokogames-projects.vercel.app/api/auth/session should not be empty
This expected behavior can always be reproduced on localhost but not on Vercel