nextauthjs / next-auth

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

OAuthCallbackError: OAuth Provider returned an error #9966

Open trevorpfiz opened 9 months ago

trevorpfiz commented 9 months ago

Environment

System: OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa) CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor Memory: 5.44 GB / 9.72 GB Container: Yes Shell: 5.8 - /usr/bin/zsh Binaries: Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm pnpm: 9.0.0-alpha.1 - ~/.local/share/pnpm/pnpm bun: 1.0.14 - ~/.local/share/pnpm/bun Watchman: 2024.01.22.00 - /home/linuxbrew/.linuxbrew/bin/watchman

Reproduction URL

https://github.com/t3-oss/create-t3-turbo

Describe the issue

[auth][error] OAuthCallbackError: OAuth Provider returned an error .Read more at https://errors.authjs.dev#oauthcallbackerror
    at handleOAuth (webpack-internal:///(rsc)/../../node_modules/@auth/core/lib/actions/callback/oauth/callback.js:55:15)
    at async Module.callback (webpack-internal:///(rsc)/../../node_modules/@auth/core/lib/actions/callback/index.js:35:41)
    at async AuthInternal (webpack-internal:///(rsc)/../../node_modules/@auth/core/lib/index.js:42:24)
    at async Auth (webpack-internal:///(rsc)/../../node_modules/@auth/core/index.js:126:29)
    at async eval (webpack-internal:///(rsc)/../../node_modules/next/dist/esm/server/future/route-modules/app-route/module.js:218:37)
    at async AppRouteRouteModule.execute (webpack-internal:///(rsc)/../../node_modules/next/dist/esm/server/future/route-modules/app-route/module.js:157:26)
    at async AppRouteRouteModule.handle (webpack-internal:///(rsc)/../../node_modules/next/dist/esm/server/future/route-modules/app-route/module.js:280:30)
    at async EdgeRouteModuleWrapper.handler (webpack-internal:///(rsc)/../../node_modules/next/dist/esm/server/web/edge-route-module-wrapper.js:92:21)
    at async adapter (webpack-internal:///(rsc)/../../node_modules/next/dist/esm/server/web/adapter.js:176:16)
    at async runWithTaggedErrors (/home/spark/projects/create-t3-turbo/node_modules/next/dist/server/web/sandbox/sandbox.js:99:24)
 ⨯ Error [TypeError]: immutable
    at _Headers.delete (file:///home/spark/projects/create-t3-turbo/node_modules/next/dist/compiled/edge-runtime/index.js:1:657096)
    at runWithTaggedErrors (file:///home/spark/projects/create-t3-turbo/node_modules/next/dist/server/web/sandbox/sandbox.js:106:43)
    at async DevServer.runEdgeFunction (file:///home/spark/projects/create-t3-turbo/node_modules/next/dist/server/next-server.js:1177:24)
    at async NextNodeServer.handleCatchallRenderRequest (file:///home/spark/projects/create-t3-turbo/node_modules/next/dist/server/next-server.js:247:37)
    at async DevServer.handleRequestImpl (file:///home/spark/projects/create-t3-turbo/node_modules/next/dist/server/base-server.js:807:17)
    at async (file:///home/spark/projects/create-t3-turbo/node_modules/next/dist/server/dev/next-dev-server.js:331:20)
    at async Span.traceAsyncFn (file:///home/spark/projects/create-t3-turbo/node_modules/next/dist/trace/trace.js:151:20)
    at async DevServer.handleRequest (file:///home/spark/projects/create-t3-turbo/node_modules/next/dist/server/dev/next-dev-server.js:328:24)
    at async invokeRender (file:///home/spark/projects/create-t3-turbo/node_modules/next/dist/server/lib/router-server.js:163:21)
    at async handleRequest (file:///home/spark/projects/create-t3-turbo/node_modules/next/dist/server/lib/router-server.js:342:24)

How to reproduce

click 'Sign in with Discord'. click the cancel button on the Discord signin page. see error.

Expected behavior

it should send back to something like https://turbo.t3.gg/api/auth/signin?error=OAuthCallbackError. instead it is this http://localhost:3000/api/auth/callback/discord?error=access_denied&error_description=The+resource+owner+or+authorization+server+denied+the+request

trevorpfiz commented 9 months ago

only getting this error in development it seems.

trevorpfiz commented 9 months ago

https://www.loom.com/share/7d8d95668bc8422b99c9f28b45197ec2?sid=38bf4433-9c53-4ccc-a364-c1e615fddc1e

dmarcucci commented 9 months ago

Having the same issue with CredentialsProvider.

Noticed https://github.com/nextauthjs/next-auth/issues/9869 reporting something similar, so I removed export const runtime = 'edge' in my route.ts to see what would happen. It worked and showed the default error message as expected.

trevorpfiz commented 9 months ago

can confirm that export const runtime = "edge" is causing this error

Flammae commented 1 month ago

Having the same error with Drizzle adapter and Google provider. Discord provider works properly.