nextauthjs / next-auth

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

Next-Auth not working with Next.js latest v13.4.13: TypeError: cookie is not iterable #8315

Closed brandon-kong closed 1 year ago

brandon-kong commented 1 year ago

Environment

System: OS: Windows 10 10.0.19045 CPU: (12) x64 AMD Ryzen 5 3600X 6-Core Processor Memory: 5.74 GB / 15.91 GB Binaries: Node: 18.14.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD npm: 9.5.0 - ~\AppData\Roaming\npm\npm.CMD Browsers: Edge: Spartan (44.19041.1266.0), Chromium (115.0.1901.203) Internet Explorer: 11.0.19041.1566

Reproduction URL

https://github.com/brandon-kong/next-auth-next-test

Describe the issue

The latest version of Next-Auth as of August 13, 2023 is not compatible with Next.js v13.4.13. When attempting to go to /api/auth/signin OR use Next-Auth's session functions like getServerSession, signIn, getSession, etc..., the server output dumps:

TypeError: cookies is not iterable at node:internal/deps/undici/undici:1865:43 at Headers Iterator.next (node:internal/deps/undici/undici:1108:26)

I have tried:

As soon as I reverted Next.js' version to 13.4.12, the preceding version of the latest, Next-Auth worked again.

An easy way to avoid this issue is to just not use Next.js v13.4.13. However, it is likely that future updates to Next.js will not be compatible with Next-Auth as well.

How to reproduce

  1. Create a new Next.js project with the latest create-next-app version which will initialize a 13.4.13 project (as of this issue's creation). Note that using the App Router or Page Router will not matter.
  2. Install next-auth normally: npm i next-auth
  3. Set up next-auth in the project as the documentation specifically instructs.
  4. After next-auth is configured in your project, run the development server with npm run dev and navigate to http://localhost:3000/api/auth/signin.
  5. A 500 Internal Error will be displayed on the screen, and the TypeError mentioned in the title and in the issue brief will be displayed in the server console.

Additionally, you could also clone the next-auth-example repository: https://github.com/nextauthjs/next-auth-example After running npm install and npm run dev and attempting to use next-auth, you will come across the same error.

Expected behavior

Visiting /api/auth/signin should display the default Next-Auth sign-in page will all the provider forms for signing in.

sshah98 commented 1 year ago

getting the same error

balazsorban44 commented 1 year ago

Tried to reproduce it, but it works correctly, logged in successfully.

image

image

Please open a new issue with a proper reproduction.

brandon-kong commented 1 year ago

@balazsorban44 Interesting... If you selectively install next v13.4.13 with npm i next@13.4.13, are you also able to get the same results?

Here's the output I got from following my reproduction steps on a different device than the one in the environment section: https://github.com/nextauthjs/next-auth/assets/95515854/cc3a95f9-9761-4621-8223-52fe2afc118e

Update: Interestingly enough, I reverted back to 13.14.12, deleted node_modules and installed next@latest, and it seemed to work. Nonetheless, this seems to be a circumstantial issue that doesn't consistently happen. Does this seem like something to bat an eye to?

M0lion commented 1 year ago

Try upgrading node https://github.com/nodejs/node/issues/46704 I had the same problem with same node version( or at least similar version ) upgrading fixed it.

yarrichar commented 1 year ago

Same - upgrading to 18.17.1 worked for me

Putaolaozu commented 1 year ago

I also had the same issue with next.js 13.4.17, and I had tried different version of nodejs (both 18.17.1 and 19.6.1), but diden't work for me. I finally change my next.js to version 13.4.12, and the issue has magically gone.

gamemann commented 11 months ago

Upgrading NodeJS to 18.17.1 fixed this issue for me as well.

@yarrichar Thank you!

hugok2k commented 11 months ago

Thank you @yarrichar

JulianDM1995 commented 11 months ago

Next v13.4.19 - Node 19.6.1, does not work.

Nisfan commented 11 months ago

Next v13.4.19 - Node v19.6.1 does not work Next v13.4.19 - Node v18.17.1 works fine

ryoon-with-wisdomtrees commented 11 months ago

Next v13.4.19 - Node v18.14.1 does not work Next v13.4.19 - Node v18.17.1 works fine

codecodeworld22 commented 9 months ago

Next v14.0.0 - Node v18.17.1 doesn't work next-auth

ghost commented 9 months ago

Next v14.0.0 - Node v18.17.1 doesn't work next-auth

same here !

codecodeworld22 commented 9 months ago

Next-Auth v4.24.4 is now ok to install on Next v14.0.0, well done guys!

ghost commented 9 months ago

Next-Auth v4.24.4 is now ok to install on Next v14.0.0, well done guys!

thanks for telling us, will try it out. good luck !