nextauthjs / next-auth

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

defaultCookies is not defined #4709

Closed mike-webdev closed 2 years ago

mike-webdev commented 2 years ago

Question šŸ’¬

Hi I'm using next-auth version: 3.27.3 I suddenly got this error while running my app. Anyone encountered this? Thank you.

error - unhandledRejection: ReferenceError: defaultCookies is not defined
    at C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\node_modules\next-auth\dist\server\index.js:102:9
    at new Promise (<anonymous>)
    at NextAuthHandler (C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\node_modules\next-auth\dist\server\index.js:67:10)
    at NextAuth (C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\node_modules\next-auth\dist\server\index.js:299:10)
    at __WEBPACK_DEFAULT_EXPORT__ (C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\.next\server\pages\api\auth\[...nextauth].js:188:128)
    at Object.apiResolver (C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\node_modules\next\dist\server\api-utils.js:101:15)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async DevServer.handleApiRequest (C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\node_modules\next\dist\server\next-server.js:775:9)
    at async Object.fn (C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\node_modules\next\dist\server\next-server.js:666:37)

How to reproduce ā˜•ļø

npm run dev

Contributing šŸ™ŒšŸ½

No, I am afraid I cannot help regarding this

untillnesss commented 2 years ago

I also get an error like that, even though previously the application was running fine.

image

balazsorban44 commented 2 years ago

Hi, v3 is an unmaintained version. Please upgrade to v4 and report back if you still experience the issue.

mike-webdev commented 2 years ago

The solution here is a hassle to many users.

chaudev commented 2 years ago

Hi, v3 is an unmaintained version. Please upgrade to v4 and report back if you still experience the issue.

I have a similar problem, my project is running fine on v3 and when I upgrade to v4 it crashes in many places. Why this absurdity? Shouldn't the old version still work?

Fleeb commented 2 years ago

We are expecting the old version to still work since nothing was changed - even if v3 is an unmaintained version.

fabien commented 2 years ago

Same error here, nothing changed on the codebase (and using older v3), my client just did another deploy due to CMS updates. This is unacceptable.

[POST] /api/auth/_log
20:14:15:50
2022-06-14T18:14:18.805Z    8563085b-526b-4d39-bb06-b37d643e1344    ERROR   Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"ReferenceError: defaultCookies is not defined","reason":{"errorType":"ReferenceError","errorMessage":"defaultCookies is not defined","stack":["ReferenceError: defaultCookies is not defined","    at /var/task/node_modules/next-auth/dist/server/index.js:102:9","    at new Promise (<anonymous>)","    at NextAuthHandler (/var/task/node_modules/next-auth/dist/server/index.js:67:10)","    at NextAuth (/var/task/node_modules/next-auth/dist/server/index.js:299:10)","    at /var/task/.next/server/chunks/5599.js:546:64","    at Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils/node.js:185:15)","    at processTicksAndRejections (internal/process/task_queues.js:95:5)","    at async NextNodeServer.runApi (/var/task/node_modules/next/dist/server/next-server.js:395:9)","    at async Object.fn (/var/task/node_modules/next/dist/server/base-server.js:496:37)","    at async Router.execute (/var/task/node_modules/next/dist/server/router.js:226:36)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: ReferenceError: defaultCookies is not defined","    at process.<anonymous> (/var/runtime/index.js:35:15)","    at process.emit (events.js:412:35)","    at processPromiseRejections (internal/process/promises.js:245:33)","    at processTicksAndRejections (internal/process/task_queues.js:96:32)"]}
Unknown application error occurred

EDIT I downgraded next-auth explicitly to version 3.29.3 (was ^3.29.3 before) and now it works!

hawkyre commented 2 years ago

I've just got the same problem, can't upgrade because I'm using the firebase adapter. Downgrading to 3.29.3 works. Thanks, fabien!

mike-webdev commented 2 years ago

Upgrading from 3.27.3 to 3.29.3 works for me too . Thanks!

anargiris commented 2 years ago

I've been having problems with the same exact error (client needed updates on their site but kept getting this error).

Changing version from ^3.29.0 to 3.29.3 fixed the issue. Would love to know more information about this and what caused the error.

mike-webdev commented 2 years ago

Seems to work at first try but when I clone a new project, the error is still there.

liorkesos commented 2 years ago

This is broken for me also in 4.5.0

iamharshad commented 2 years ago

Same error here, nothing changed on the codebase (and using older v3), my client just did another deploy due to CMS updates. This is unacceptable.

[POST] /api/auth/_log
20:14:15:50
2022-06-14T18:14:18.805Z  8563085b-526b-4d39-bb06-b37d643e1344    ERROR   Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"ReferenceError: defaultCookies is not defined","reason":{"errorType":"ReferenceError","errorMessage":"defaultCookies is not defined","stack":["ReferenceError: defaultCookies is not defined","    at /var/task/node_modules/next-auth/dist/server/index.js:102:9","    at new Promise (<anonymous>)","    at NextAuthHandler (/var/task/node_modules/next-auth/dist/server/index.js:67:10)","    at NextAuth (/var/task/node_modules/next-auth/dist/server/index.js:299:10)","    at /var/task/.next/server/chunks/5599.js:546:64","    at Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils/node.js:185:15)","    at processTicksAndRejections (internal/process/task_queues.js:95:5)","    at async NextNodeServer.runApi (/var/task/node_modules/next/dist/server/next-server.js:395:9)","    at async Object.fn (/var/task/node_modules/next/dist/server/base-server.js:496:37)","    at async Router.execute (/var/task/node_modules/next/dist/server/router.js:226:36)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: ReferenceError: defaultCookies is not defined","    at process.<anonymous> (/var/runtime/index.js:35:15)","    at process.emit (events.js:412:35)","    at processPromiseRejections (internal/process/promises.js:245:33)","    at processTicksAndRejections (internal/process/task_queues.js:96:32)"]}
Unknown application error occurred

EDIT I downgraded next-auth explicitly to version 3.29.3 (was ^3.29.3 before) and now it works!

This works for me

lcschy commented 2 years ago

@balazsorban44 This is still broken and now the patch version for CVE-2022-31093 also includes this error. There is currently no way for anyone on v3 to avoid this vulnerability. This commenter has pinpointed the error so I think this should be addressed: https://github.com/nextauthjs/next-auth/commit/87f6f576b1f31249868991a2d1fecc4a9e4f5ce8#r75837858

balazsorban44 commented 2 years ago

I'll have a look, thanks... Note that v3 has been unmaintained for a while now, even the security advisory points out that you should upgrade to v4, at some point (probably soon) we will stop patching v3.

This is broken for me also in 4.5.0

If the issue happens in v4, that will be priority. cc @ThangHuuVu

balazsorban44 commented 2 years ago

3.29.6 should include this fix: https://github.com/nextauthjs/next-auth/pull/4711, still unable to reproduce anything similar in v4.

MohammadWawan commented 8 months ago

i'm have error of the auth, the error is like this {"message":"There is a problem with the server configuration. Check the server logs for more information."}. help me to solve it.