-
Notifications
You must be signed in to change notification settings - Fork 46
[BUG] NextAuth signOut request takes 15 seconds in preview mode #686
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
Comments
You could make this reproduction not require OAuth by using this as your |
This seems to be a bigger scope than just
|
https://github.com/vercel/next.js/blob/6b1e48080e896e0d44a05fe009cb79d2d3f91774/packages/next/src/server/app-render/action-handler.ts#L337-L345 - it seems to hit the catch here: URL {
origin: 'https://localhost:8787',
href: 'https://localhost:8787/api/auth/signin?callbackUrl=http%3A%2F%2Flocalhost%3A8787%2F',
protocol: 'https:',
username: '',
password: '',
host: 'localhost:8787',
hostname: 'localhost',
port: '8787',
pathname: '/api/auth/signin',
search: '?callbackUrl=http%3A%2F%2Flocalhost%3A8787%2F',
hash: '',
searchParams: URLSearchParams(1) { 'callbackUrl' => 'http://localhost:8787/' }
} The problem seems to be this line: https://github.com/vercel/next.js/blob/6b1e48080e896e0d44a05fe009cb79d2d3f91774/packages/next/src/server/app-render/action-handler.ts#L314-L315 - You can replace it with this to solve the issue: const fetchUrl = new URL(
`http://localhost:8787${appRelativeRedirectUrl.pathname}${appRelativeRedirectUrl.search}`
) Not sure how it should be handled. It turns out Next uses this environment variable ( |
@Macil A workaround until there is a better solution would be update your "env": {
"preview": {
"vars": {
"__NEXT_PRIVATE_ORIGIN": "http://localhost:8787"
// you might want this aswell
// "AUTH_URL": "http://localhost:8787"
}
},
}, Then to run in preview mode you can do |
Thanks, that workaround works. Yeah, I previously noticed that I also have to set the environment variable |
Your probably right the edge converter should consider setting the I'll open a PR on it. |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
If you make a sign-out button with Auth.js/NextAuth and then use it while running your project with
npm run preview
(which uses Cloudflare wrangler and supports durable objects with rpc unlikenpm run dev
), the request to sign you out takes 15 seconds to complete, and this error shows up in the terminal:This issue does not affect applications in production deployed to Cloudflare Workers or run locally with
npm run dev
. I'm a little surprised thatnpm run preview
is the odd one out since generally it seems likenpm run preview
is the development option that works most closely to Cloudflare Workers.Steps to reproduce
A simple example project reproducing this bug is at https://github.com/Macil/next-auth-test. The project is a fresh OpenNext Cloudflare template with a straight-forward usage of NextAuth from following NextAuth's documentation. I've kept the git history clean so you can easily see exactly what was done.
The
signOut()
function is called in a server action incomponents/SignOut.tsx
, following the example given in NextAuth's docs at https://authjs.dev/getting-started/session-management/login.Expected behavior
Calling NextAuth's
signOut()
function in a server action should be quick and not log any errors when used undernpm run preview
.@opennextjs/cloudflare version
1.0.4
Wrangler version
4.17.0
next info output
Operating System: Platform: linux Arch: x64 Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024 Available memory (MB): 31694 Available CPU cores: 32 Binaries: Node: 23.6.1 npm: 11.0.0 Yarn: N/A pnpm: N/A Relevant Packages: next: 15.3.2 // Latest available version is detected (15.3.2). eslint-config-next: 15.3.2 react: 19.1.0 react-dom: 19.1.0 typescript: 5.8.3 Next.js Config: output: N/A
Additional context
It might be worth noting that there is a separate OpenNext/NextAuth bug affecting signout (#606) that this repository has a workaround in place for in
open-next.config.ts
. I do not think that bug is directly related to the 15 second delay but I might be wrong. The delay is present with or without this workaround.The text was updated successfully, but these errors were encountered: