Closed chungweileong94 closed 7 months ago
The problem seems to be caused by new NextRequest(...)
in reqWithEnvURL
https://github.com/nextauthjs/next-auth/blob/8a2ca6b280457f202ff77f74dc699cbf85606d43/packages/next-auth/src/lib/env.ts#L11
Which is why setting either AUTH_URL
or NEXTAUTH_URL
will bypass the problem.
I can confirm this bug, same setup
Related to #9795. This sounds like an upstream Next.js bug which I thought has been fixed. Will have a look there. The workaround is to patch new NextRequest
to new NextRequest.default
for now, or drop the env variables.
Note: You most likely don't need AUTH_URL
or NEXTAUTH_URL
anyway, it's not been required for a very long time, unless you want a custom path for your auth route, or behind a proxy.
Note: You most likely don't need
AUTH_URL
orNEXTAUTH_URL
, it's not been required for a very long time, unless you want a custom path for your auth route, or behind a proxy.
Ah, good to know.
Fix is on the way in Next.js https://github.com/vercel/next.js/pull/61721
Will close this issue, as it has been fixed in the latest NextJS canary release.
Note: You most likely don't need
AUTH_URL
orNEXTAUTH_URL
anyway, it's not been required for a very long time, unless you want a custom path for your auth route, or behind a proxy.
Thing is, I do use a proxy because I am working with a Docker container and using nginx to deploy the app. What are my options in this case?
EDIT: Nevermind my message, I was able to make the auth work using NEXTAUTH_URL_INTERNAL instead.
Hi @Zelzazor , can you please tell me how you were able to make the auth work using NEXTAUTH_URL_INTERNAL, thanks.
Hi @Zelzazor , can you please tell me how you were able to make the auth work using NEXTAUTH_URL_INTERNAL, thanks.
I was able to apply a fix for local dev at least by changing:
AUTH_URL=***********
to
NEXTAUTH_URL_INTERNAL=***********
in my .env file. If you don't have AUTH_URL perhaps add NEXTAUTH_URL_INTERNAL instead of replacing
Thanks, btw my error resolved when i shifted to previous version 5.0.0-beta.4 from 5.0.0-beta.8
I am still getting this error. I tried adding AUTH_URL , NEXTAUTH_URL_INTERNAL and still keep getting this error.
@bwheeele This is an upstream Next.js bug, which has been fixed in https://github.com/vercel/next.js/pull/61721, and landed in the latest Next.js canary version, but yet to be landed in the stable version.
@chungweileong94 just installed 14.1.1-canary.73
and it resolved the issue for me. Thank you!
I've encountered a potential edge case when using the prisma adapter together with prisma accelerate and the following versions in my project:
@prisma/client: ^5.10.2 @prisma/extension-accelerate: ^0.6.3 next-auth: ^5.0.0-beta.13 next: ^14.1.0,
I observed that this issue was resolved when I set the route handler to run on the edge.
This doesn't work:
import { auth } from "@/server/auth";
export const GET = auth(async (req) => {
const session = req.auth
...
return Response.json({data})
})
This works:
import { auth } from "@/server/auth";
export const runtime = 'edge';
export const GET = auth(async (req) => {
const session = req.auth
...
return Response.json({data})
})
Hi @Zelzazor , can you please tell me how you were able to make the auth work using NEXTAUTH_URL_INTERNAL, thanks.
I was able to apply a fix for local dev at least by changing:
AUTH_URL=***********
to
NEXTAUTH_URL_INTERNAL=***********
in my .env file. If you don't have AUTH_URL perhaps add NEXTAUTH_URL_INTERNAL instead of replacing
This is what fixed it for me on "next-auth": "^5.0.0-beta.17"
This is what fixed it for me on
"next-auth": "^5.0.0-beta.17"
God, bless you! Thanks a million.
Environment
Reproduction URL
https://github.com/chungweileong94/nextauth-route-handler-error
Describe the issue
If one of the
AUTH_URL
andNEXTAUTH_URL
is set, we will get the following error.How to reproduce
pnpm dev
http://localhost:3000/api/auth/signin
Expected behavior
It should show the next-auth built-in sign-in page. Instead, it shows throw 500 error (
TypeError: next_dist_server_web_exports_next_request__WEBPACK_IMPORTED_MODULE_0__ is not a constructor
)