-
-
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
In authorized callback auth object is null all the time #9097
Comments
I encountered the same problem. Adding AUTH_URL to the environment variables solved it. |
Thank you, it works. |
Confirmed also works for me. Was encountering this with my localhost:3000 while auth worked as expected in prod vercel site. Vercel must automatically set an AUTH_URL env variable? Working example: AUTH_URL="http://localhost:3000" |
Thanks @apshenichniy! |
add |
I experienced the same issue. In my case it's due to same-site origin policy that prevents exchanging cookies which leads to // This will work
return await fetch(
`/api/payments`,
{
method: "POST",
body: JSON.stringify(data),
}
);
// This will not work as expected
return await fetch(
`http://127.0.0.1:3000/api/payments`,
{
method: "POST",
body: JSON.stringify(data),
}
); |
Adding // auth.ts
import NextAuth from "next-auth";
import Google from "next-auth/providers/google";
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [Google],
pages: {
signIn: "/",
error: "/",
},
callbacks: {
authorized: async ({ auth }) => {
console.log("🍉 ~ authorized: ~ auth:", auth);
console.log(
"🍉 ~ authorized: ~ process.env.AUTH_URL:",
process.env.AUTH_URL,
);
// return Promise.resolve(!!auth);
return {};
},
// redirect: () => {
// return "/admin";
// },
},
}); |
Environment
System:
OS: Windows 11 10.0.22631
CPU: (12) x64 AMD Ryzen 5 5500U with Radeon Graphics
Memory: 5.76 GB / 15.38 GB
Binaries:
Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.9.2 - ~\AppData\Roaming\npm\pnpm.CMD
Browsers:
Edge: Chromium (119.0.2151.44)
Internet Explorer: 11.0.22621.1
npmPackages:
next: ^14.0.1 => 14.0.1
next-auth: ^5.0.0-beta.3 => 5.0.0-beta.3
react: 18.2.0 => 18.2.0
Reproduction URL
https://github.com/nextauthjs/next-auth-example/blob/main/auth.ts
Describe the issue
After login with credentials, in the authorized callback I can't access auth object, all time auth object is null but when I check cookies the session token is present
How to reproduce
use credentials provider
Expected behavior
the auth object should not be empty or null after login
The text was updated successfully, but these errors were encountered: