nextjs-auth0: 4.0.0-beta.2 getSession returns null
Checklist
- The issue can be reproduced in the nextjs-auth0 sample app (or N/A).
- I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- I have looked into the API documentation and have not found a suitable solution or answer.
- I have searched the issues and have not found a suitable solution or answer.
- I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- I agree to the terms within the Auth0 Code of Conduct.
Description
following the documentation on the readme for login. Everything works correctly redirecting to /auth/login and back. No errors on the callback. In the onCallback there is a session object. When you are on a server component and run the below code it returns null for the session
Reproduction
- setup per instructions on the readme
- go to child route using app router and use the following code
import { auth0 } from "@/lib/auth0"
const session = await auth0.getSession()
return ( <> <main> <h1>Welcome, {session.user.name}!</h1> </main> );
Additional context
No response
nextjs-auth0 version
4.0.0-beta.2
Next.js version
15.0.3
Node.js version
22.9.0
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 28 (11 by maintainers)
Definitely, I’ll update the docs so it’s more clear — thanks for the feedback!
Hi @guabu, just want to confirm that today I’ve re run the same use case and now it’s working correctly. I fear that this was caused by a misconfiguration on the callback url. I was testing using
localhostas callback, but the experiment that gave getSession null was executed with a mobile phone connected on the same wifi. So when I ran the experiment reaching the site on192.168.1.66the callback redirected towardslocalhost:3000/auth/callback?code=1234..., giving no chance to the nextjs app to authenticate correctly the user. I apologize for adding noise, I think this is the expected behaviour from nextjs-auth0. Thanks and have a beautiful day