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

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.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 4
  • Comments: 15 (1 by maintainers)

Most upvoted comments

Same - upgrading to 18.17.1 worked for me

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

image

image

Please open a new issue with a proper reproduction.

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

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

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

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

Thank you @yarrichar

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.

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.