Skip to content
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

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

Closed
brandon-kong opened this issue Aug 14, 2023 · 15 comments
Labels
triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@brandon-kong
Copy link

brandon-kong commented Aug 14, 2023

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:

  • Clearing .next cache
  • Changing browsers
  • Clearing browser cookies and cache
  • Going from App Router to Page Router
  • Reverting to previous Next-Auth version.
  • Pouring boiling hot water over my keyboard
  • Switching to a different OS

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.

@brandon-kong brandon-kong added the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Aug 14, 2023
@brandon-kong brandon-kong changed the title TypeError: cookie is not iterable in Next.js v13.4.13 Next-Auth not working with Next.js latest v13.4.13: TypeError: cookie is not iterable Aug 14, 2023
@sshah98

This comment was marked as spam.

@balazsorban44
Copy link
Member

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

image

image

Please open a new issue with a proper reproduction.

@brandon-kong
Copy link
Author

brandon-kong commented Aug 14, 2023

@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
Copy link

M0lion commented Aug 16, 2023

Try upgrading node
nodejs/node#46704
I had the same problem with same node version( or at least similar version ) upgrading fixed it.

@yarrichar
Copy link

Same - upgrading to 18.17.1 worked for me

@Putaolaozu
Copy link

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
Copy link

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

@yarrichar Thank you!

@hugok2k
Copy link

hugok2k commented Sep 2, 2023

  • Next v13.4.19 - Node 18.14.1, does not work.
  • Next v13.4.19 - Node 18.17.1, works perfectly 💪

Thank you @yarrichar

@JulianDM1995
Copy link

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

@Nisfan
Copy link

Nisfan commented Sep 8, 2023

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

@ryoonwithinwisdomlights

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

@codecodeworld22
Copy link

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

@ghost
Copy link

ghost commented Oct 27, 2023

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

same here !

@codecodeworld22
Copy link

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

@ghost
Copy link

ghost commented Oct 28, 2023

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests