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

Build fails with v4.18.5 using middleware #6025

Closed
aq-saito opened this issue Dec 12, 2022 · 9 comments
Closed

Build fails with v4.18.5 using middleware #6025

aq-saito opened this issue Dec 12, 2022 · 9 comments
Labels
bug Something isn't working middleware Related to middleware

Comments

@aq-saito
Copy link

Environment

System:
OS: Linux 5.15 Ubuntu 20.04.5 LTS (Focal Fossa)
CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700KF
Memory: 12.22 GB / 15.53 GB
Container: Yes
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.18.0 - ~/.asdf/installs/nodejs/16.18.0/bin/node
Yarn: 1.22.19 - ~/.asdf/installs/nodejs/16.18.0/bin/yarn
npm: 8.19.2 - ~/.asdf/plugins/nodejs/shims/npm
npmPackages:
next: 13.0.6 => 13.0.6
next-auth: 4.18.5 => 4.18.5
react: 18.2.0 => 18.2.0

Reproduction URL

https://github.com/nextauthjs/next-auth-example

Describe the issue

npm run build starts failing to build after upgrading next-auth to v4.18.5 if the project uses next-auth/middleware.

Even the official example repository next-auth-example cannot be built with the latest version of next-auth.

$ npm run build

> build
> next build

info  - Linting and checking validity of types
info  - Creating an optimized production build
Failed to compile.

./node_modules/@babel/runtime/regenerator/index.js
Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation

Import trace for requested module:
./node_modules/@babel/runtime/regenerator/index.js
./node_modules/next-auth/core/errors.js
./node_modules/next-auth/utils/web.js
./node_modules/next-auth/next/middleware.js
./node_modules/next-auth/middleware.js

How to reproduce

$ git clone https://github.com/nextauthjs/next-auth-example
$ cd next-auth-example
$ npm install
$ npm run build

Expected behavior

npm run build is done without any errors.

@aq-saito aq-saito added the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Dec 12, 2022
@Nayeem-XTREME
Copy link

Faced same issue after upgrading to 4.18.5

@balazsorban44 balazsorban44 added bug Something isn't working middleware Related to middleware and removed triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Dec 12, 2022
ThangHuuVu pushed a commit to ThangHuuVu/next-auth that referenced this issue Dec 12, 2022
* fix(core): properly construct url (nextauthjs#5984)

* chore(release): bump package version(s) [skip ci]

* fix(core): add protocol if missing

* fix(core): throw error if no action can be determined

* test(core): fix test

* chore(release): bump package version(s) [skip ci]

* chore(docs): add new tutorial (nextauthjs#5604)

Co-authored-by: Nico Domino <[email protected]>

* fix(core): handle `Request` -> `Response` regressions  (nextauthjs#5991)

* fix(next): don't override `Content-Type` by `unstable_getServerSession`

* fix(core): handle `,` while setting `set-cookie`

* chore(release): bump package version(s) [skip ci]

* fix(sequelize): increase sequelize `id_token` column length (nextauthjs#5929)

Co-authored-by: Nico Domino <[email protected]>

* fix(core): correct status code when returning redirects (nextauthjs#6004)

* fix(core): correctly set status when returning redirect

* update tests

* forward other headers

* update test

* remove default 200 status

* fix(core): host detection/NEXTAUTH_URL (nextauthjs#6007)

* rename `host` to `origin` internally

* rename `userOptions` to `authOptions` internally

* use object for `headers` internally

* default `method` to GET

* simplify `unstable_getServerSession`

* allow optional headers

* revert middleware

* wip getURL

* revert host detection

* use old `detectHost`

* fix/add some tests wip

* move more to core, refactor getURL

* better type auth actions

* fix custom path support (w/ api/auth)

* add `getURL` tests

* fix email tests

* fix assert tests

* custom base without api/auth, with trailing slash

* remove parseUrl from assert.ts

* return 400 when wrong url

* fix tests

* refactor

* fix protocol in dev

* fix tests

* fix custom url handling

* add todo comments

* chore(release): bump package version(s) [skip ci]

* update lock file

* fix(next): correctly bundle next-auth/middleware
fixes nextauthjs#6025

* fix(core): preserve incoming set cookies (nextauthjs#6029)

* fix(core): preserve `set-cookie` by the user

* add test

* improve req/res mocking

* refactor

* fix comment typo

* chore(release): bump package version(s) [skip ci]

* make logos optional

* sync with `next-auth`

* clean up `next-auth/edge`

* sync

Co-authored-by: Balázs Orbán <[email protected]>
Co-authored-by: Thomas Desmond <[email protected]>
Co-authored-by: Nico Domino <[email protected]>
Co-authored-by: Cyril Perraud <[email protected]>
balazsorban44 added a commit that referenced this issue Dec 13, 2022
* WIP use `Request` and `Response` for core

* bump Next.js

* rename ts types

* refactor

* simplify

* upgrade Next.js

* implement body reader

* use `Request`/`Response` in `next-auth/next`

* make linter happy

* revert

* fix tests

* remove workaround for middleware return type

* return session in protected api route example

* don't export internal handler

* fall back host to localhost

* refactor `getBody`

* refactor `next-auth/next`

* chore: add `@edge-runtime/jest-environment`

* fix tests, using Node 18 as runtime

* fix test

* remove patch

* upgrade/add dependencies

* type and default import on one line

* don't import all adapters by default in dev

* simplify internal endpoint config

Instead of passing url and params around as a string and an object,
we parse them into a `URL` instance.

* assert if both endpoint and issuer config is missing

* allow internal redirect to be `URL`

* mark clientId as always internally, fix comments

* add web-compatible authorization URL handling

* fix type

* fix neo4j build

* remove new-line

* reduce file changes in the PR

* simplify types

* refactor `crypto` usage

In Node.js, inject `globalThis.crypto` instead of import

* add `next-auth/web`

* refactor

* send header instead of body to indicate redirect response

* fix eslint

* fix tests

* chore: upgrade dep

* fix import

* refactor: more renames

* wip core

* support OIDC

* remove `openid-client`

* temprarily remove duplicate logos

* revert

* move redirect logic to core

* feat: add sveltekit auth

* wip fix css

* revert Logo component

* output ESM

* fix logout

* deprecate OAuth 1,  simplify internals, improve defaults

* refactor providers, test facebook

* fix providers

* target es2020

* fix CSS

* fix AuthHandler, add getServerSession

* update lock file

* make logos optional

* sync with `next-auth`

* clean up `next-auth/edge`

* sync

* Sync (#2)

* fix(core): properly construct url (#5984)

* chore(release): bump package version(s) [skip ci]

* fix(core): add protocol if missing

* fix(core): throw error if no action can be determined

* test(core): fix test

* chore(release): bump package version(s) [skip ci]

* chore(docs): add new tutorial (#5604)

Co-authored-by: Nico Domino <[email protected]>

* fix(core): handle `Request` -> `Response` regressions  (#5991)

* fix(next): don't override `Content-Type` by `unstable_getServerSession`

* fix(core): handle `,` while setting `set-cookie`

* chore(release): bump package version(s) [skip ci]

* fix(sequelize): increase sequelize `id_token` column length (#5929)

Co-authored-by: Nico Domino <[email protected]>

* fix(core): correct status code when returning redirects (#6004)

* fix(core): correctly set status when returning redirect

* update tests

* forward other headers

* update test

* remove default 200 status

* fix(core): host detection/NEXTAUTH_URL (#6007)

* rename `host` to `origin` internally

* rename `userOptions` to `authOptions` internally

* use object for `headers` internally

* default `method` to GET

* simplify `unstable_getServerSession`

* allow optional headers

* revert middleware

* wip getURL

* revert host detection

* use old `detectHost`

* fix/add some tests wip

* move more to core, refactor getURL

* better type auth actions

* fix custom path support (w/ api/auth)

* add `getURL` tests

* fix email tests

* fix assert tests

* custom base without api/auth, with trailing slash

* remove parseUrl from assert.ts

* return 400 when wrong url

* fix tests

* refactor

* fix protocol in dev

* fix tests

* fix custom url handling

* add todo comments

* chore(release): bump package version(s) [skip ci]

* update lock file

* fix(next): correctly bundle next-auth/middleware
fixes #6025

* fix(core): preserve incoming set cookies (#6029)

* fix(core): preserve `set-cookie` by the user

* add test

* improve req/res mocking

* refactor

* fix comment typo

* chore(release): bump package version(s) [skip ci]

* make logos optional

* sync with `next-auth`

* clean up `next-auth/edge`

* sync

Co-authored-by: Balázs Orbán <[email protected]>
Co-authored-by: Thomas Desmond <[email protected]>
Co-authored-by: Nico Domino <[email protected]>
Co-authored-by: Cyril Perraud <[email protected]>

* merge

* clean up sveltekit auth handler

* upgrade playground to latest

* upgrade sveltekit auth to latest

* Some more refactoring

* feat: extract type to core and reuse in sveltekit

* remove uuid

* make secret required in dev

* remove todo comments

* pass through OAuth client options

* generate declaration map

* default env secret to AUTH_SECRET

* temporary Headers fix

* move pages to lib

* move errors to lib

* move pages/index to lib

* move routes to lib

* move init to lib

* move styles to lib

* move types to lib

* move utils to lib

* fix imports

* update ignore/clean patterns

* fix imports

* update styles ts

* update gitignore

* update exports field

* revert `next-auth`

* remove extra tsconfig files

* remove `private` from package.json

* revert

* feat sveltekit

* commit

* remove unused file, expose type

* remove nextauth_url, memoize locals.getSession

* move to dependency

* fix

* format

* fix post build

* simplify

* fix lock file

* add packages/frameworks

* update package.json

* update gitignore

* Delete .gitignore

* Update types.ts

* Update tsconfig.dev.json

* skip test

* format

* skip format/lint

Co-authored-by: Balázs Orbán <[email protected]>
Co-authored-by: Balázs Orbán <[email protected]>
Co-authored-by: Thomas Desmond <[email protected]>
Co-authored-by: Nico Domino <[email protected]>
Co-authored-by: Cyril Perraud <[email protected]>
@geekyayush
Copy link

I think I am facing the same issue but with version 4.16.4.
I opened this issue: #6089

@benramsay
Copy link

I'm using next-auth for the first time, and I'm having the same problem when building :(
Is there any tip, to not be blocked for urgent tasks, while this bug is fixed ?
Should I go to an older version (wich one) ? Thx

@geekyayush
Copy link

Is there any update on this?

@dev-isemo
Copy link

@geekyayush i had the same problem. Just discovered that the bug was fixed with version 4.18.6 i think. Works for me with the latest version 4.18.8 :)

@geekyayush
Copy link

@geekyayush i had the same problem. Just discovered that the bug was fixed with version 4.18.6 i think. Works for me with the latest version 4.18.8 :)

Hey @dev-isemo
Thanks for the suggestion.
I tried after upgrading but still it didn't work. I am trying to deploy it on Cloudflare pages.

Would it be possible for you to share your code or repo? (just the part where you have a boilerplate code)
I would really appreciate it.

Thanks!

@dev-isemo
Copy link

dev-isemo commented Jan 23, 2023

@geekyayush I think it currently doesnt work with cloudflare cause its an edge runtime (not 100% sure take it with a grain of salt). I am using docker and deploying it on a plain server.

Here is the config which works for me:

Node Version: 18.12.1
Alpine Version: 3.17
NextJS: 13.1.2
Next-auth: 4.18.8
React: 18.2.0

I think you can test it with the most simple middleware e.g.

middleware.js

export { default } from "next-auth/middleware"

@geekyayush
Copy link

@dev-isemo
I am doing the same exact thing as of now. Deploying it on my own server through docker.

I will surely try that.

@evanrosa
Copy link

evanrosa commented Jul 18, 2023

Is there any update to this? Using v 4.22.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working middleware Related to middleware
Projects
None yet
Development

No branches or pull requests

7 participants