I am using Next Auth in a Nextjs project where I am encountering a login problem after deploying in Firebase. Everything works fine except login.
This is the auth page of the Hosting URL: https://rsglobal-prod.web.app/auth
When I attempt to log in, the session cookie is created, and no error is shown in the log. But the session object still shows null
which should look like this after login:
{
"user": {
"id": "abcdefgh",
"phone": "+0123456789"
}
}
Here is the log screenshot on what happens after attempting to log in:
Sorry my reputation is so low that I can’t include an image. PLease go to the links below to see the screenshots
see login log image
On the last line, Session should show a json object. But it is still null allthough session cookie is created. Probably the Next Auth can’t retrieve the session cookie somehow.
A different URL is showing here on the 4th line instead of showing the hosting URL. Trying to expand that line, it is being seen that the request url is actually different. see the screenshot below:
See the Expanded version of 4th line of previous log image
If I try to login from this different URL, I get the expected behaviour. Session object is seen in the console, redirected to homepage and other changes are recognized as well.
See the image of Trying to login from request url
There is another URL called function URL gives the same expected behaviour.
URLS
Hosting URL: https://rsglobal-prod.web.app/auth
Request Url: https://fh-bcb288a08332bbb4—ssrrsglobalprod-gmu6ua5aya-ew.a.run.app/auth
Function URL: https://ssrrsglobalprod-gmu6ua5aya-ew.a.run.app/auth
Testing account:
Use this credentials to test login:
Phone: +8801999999999
Password: 111111
Technologies used:
- next v14.2.3
- next-auth v5.0.0beta.19
- Nodejs v20.0.0
- Firebase nextjs hosting using
firebase init hosting