nextauthjs / nextauthjs/next-auth
[auth][error] OAuthAccountNotLinked: Another account already exists with the same e-mail address
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
Environment
OS: macOS 14.5
Node: 22.9.0 - /opt/homebrew/bin/node
npm: 10.9.0 - /opt/homebrew/bin/npm
pnpm: 9.12.1 - /opt/homebrew/bin/pnpm
@auth/dynamodb-adapter: ^2.7.4 => 2.7.4
next: 15.0.3 => 15.0.3
next-auth: ^5.0.0-beta.25 => 5.0.0-beta.25
react: 19.0.0-rc-66855b96-20241106 => 19.0.0-rc-66855b96-20241106
Reproduction URL
https://github.com/veyunni/authjs_login_error
Describe the issue
The below error manifests each time I attempt to login.
[auth][error] OAuthAccountNotLinked: Another account already exists with the same e-mail address. Read more at https://errors.authjs.dev#oauthaccountnotlinked
Here is the flow where this issue manifests:
- Login via google as the auth provider.
- The DynamoDB has the details of the user.
- Logout.
- Attempt to login again. This time, the login fails with the below error:
[auth][error] OAuthAccountNotLinked: Another account already exists with the same e-mail address. Read more at https://errors.authjs.dev#oauthaccountnotlinked
at handleLoginOrRegister (webpack-internal:///(rsc)/./node_modules/@auth/core/lib/actions/callback/handle-login.js:256:23)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Module.callback (webpack-internal:///(rsc)/./node_modules/@auth/core/lib/actions/callback/index.js:80:50)
at async AuthInternal (webpack-internal:///(rsc)/./node_modules/@auth/core/lib/index.js:43:24)
at async Auth (webpack-internal:///(rsc)/./node_modules/@auth/core/index.js:130:34)
at async AppRouteRouteModule.do (/Users/work/myproject/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:10:33313)
at async AppRouteRouteModule.handle (/Users/work/myproject/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:10:40382)
at async doRender (/Users/work/myproject/node_modules/next/dist/server/base-server.js:1455:42)
at async responseGenerator (/Users/work/myproject/node_modules/next/dist/server/base-server.js:1814:28)
at async DevServer.renderToResponseWithComponentsImpl (/Users/work/myproject/node_modules/next/dist/server/base-server.js:1824:28)
at async DevServer.renderPageComponent (/Users/work/myproject/node_modules/next/dist/server/base-server.js:2240:24)
at async DevServer.renderToResponseImpl (/Users/work/myproject/node_modules/next/dist/server/base-server.js:2278:32)
at async DevServer.pipeImpl (/Users/work/myproject/node_modules/next/dist/server/base-server.js:960:25)
at async NextNodeServer.handleCatchallRenderRequest (/Users/work/myproject/node_modules/next/dist/server/next-server.js:281:17)
at async DevServer.handleRequestImpl (/Users/work/myproject/node_modules/next/dist/server/base-server.js:853:17)
at async /Users/work/myproject/node_modules/next/dist/server/dev/next-dev-server.js:373:20
at async Span.traceAsyncFn (/Users/work/myproject/node_modules/next/dist/trace/trace.js:153:20)
at async DevServer.handleRequest (/Users/work/myproject/node_modules/next/dist/server/dev/next-dev-server.js:370:24)
at async invokeRender (/Users/work/myproject/node_modules/next/dist/server/lib/router-server.js:183:21)
at async handleRequest (/Users/work/myproject/node_modules/next/dist/server/lib/router-server.js:360:24)
at async requestHandlerImpl (/Users/work/myproject/node_modules/next/dist/server/lib/router-server.js:384:13)
at async Server.requestListener (/Users/work/myproject/node_modules/next/dist/server/lib/start-server.js:142:13)
GET /api/auth/callback/google?code=4%2F0AeanS0ZI5yFIxF_TLu7vAdGyKSD-KR9A7EeAa9guyNgkUPckFgnHX7DAPzGSwEIUSsgETQ&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=0&prompt=consent 302 in 395ms
GET /api/auth/signin?error=OAuthAccountNotLinked 200 in 5ms
======================
The login page displays the below message:
"To confirm your identity, sign in with the same account you used originally."
How to reproduce
A) Clone the repository https://github.com/veyunni/authjs_login_error.
B) Update the .env/.env.local with the credentials of your google app.
C) Update the dynamodb details also.
Run the app by doing:
npm run dev
Here is the workflow where this issue manifests:
- Click login and select google as the auth provider. (The behavior was the same with Facebook provider too).
- The DynamoDB instance has the details of the user that logged on.
- Then click logout.
- Attempt to login again. This time, the login fails with the error.
Expected behavior
- Login does not fail for a new user. It is the repeat user login that fails.
- Also, if I clear the contents of the Dynamodb table, I am able to login again successfully.
With debug turned on, I can see that each time the user logs on, a new UUID is generated for the user as well as for the provider.
This is a basic workflow. what am I doing wrong? Please help.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the flow using the linked authjs_login_error repository, its Google or Facebook provider, and the DynamoDB setup. Start at the callback stack location in node_modules/@auth/core/lib/actions/callback/handle-login.js and compare the stored user and provider records before and after logout. Done means the same user can log in again without OAuthAccountNotLinked while existing DynamoDB records remain intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, node.js, react, typescript
- Domain
- authentication, backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100