nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
24.77k stars 3.49k forks source link

Issue with Provider Redirection on Firebase Hosting: Memory Leak and Errors 408/Internal Server Error #8320

Open markdagraca opened 1 year ago

markdagraca commented 1 year ago

Environment

System: OS: Windows 10 10.0.19045 CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz Memory: 36.57 GB / 63.94 GB Binaries: Node: 18.16.1 - C:\Program Files\nodejs\node.EXE
npm: 8.3.0 - C:\Program Files\nodejs\npm.CMD Browsers: Chrome: 115.0.5790.171 Edge: Spartan (44.19041.1266.0), Chromium (115.0.1901.203) Internet Explorer: 11.0.19041.1566

Reproduction URL

https://nextauthexample-4e81c.web.app/

Describe the issue

When accessing /api/auth/signin and selecting the Google provider for redirection, the server request hangs, leading to a memory leak issue. This problem also prevents the request from processing when deployed to Google Firebase Hosting, which runs a Cloud Run instance in the background. Notably, the code functions as intended when running on localhost.

Despite the memory continually increasing, no server logs are being produced. This behavior indicates a memory leak issue during data fetching.

I've opened a corresponding issue with the Firebase team for further investigation: Issue #6225.

How to reproduce

Sample Code: GitHub Repository

Steps to Reproduce:

  1. Clone the sample repository and fill out the necessary .env variables.
  2. Run the code locally, and you will notice the login should take you to the Google login page.
  3. Deploy this code to Firebase.
  4. Try accessing the page again, and you will encounter either an "Internal Server Error" or a "408 Error," preventing you from reaching the login page.

Expected behavior

When deployed to Firebase, the login process should behave the same as it does on localhost, redirecting users to the Google login page without errors. Any attempts to access the page should not result in "Internal Server Error" or "408 Error." The code should function without memory leaks or any server request hang-ups.

atkingtornado commented 1 year ago

I am having exactly the same issue (but with Discord auth provider)

atkingtornado commented 1 year ago

@markdagraca Have you been able to find a way around this issue? Thanks!

rajivos commented 1 year ago

Facing same exact issue. Could it be because Session cookie are stripped from the headers for CDNs. (https://firebase.google.com/docs/hosting/manage-cache#using_cookies)

markdagraca commented 1 year ago

@markdagraca Have you been able to find a way around this issue? Thanks!

The only work around I have found is to ditch firebase hosting and use cloud run which is much more work

graup commented 1 year ago

We've also ran into this problem. The setup experience of Next.js + Nextauth + Firebase would be amazingly simple if not for this :(

https://firebase.google.com/docs/hosting/manage-cache#using_cookies

If this is indeed the problem, it would require quite some changes in Nextauth to make it work. Seems Nextauth uses several cookies to work but in Cloud Functions we can only have one, __session?!

Related discussion: https://github.com/nextauthjs/next-auth/discussions/5301

macrozone commented 1 year ago

any workaround for that or progress?