next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

Resend email provider does not create an entry in Account table

Open gnasamx opened this issue 1 year ago • 10 comments

Provider type

Email

Environment

  • OS: macOS 14.4.1 CPU: (4) x64 Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz Memory: 152.95 MB / 8.00 GB Shell: 5.9 - /bin/zsh
  • Binaries: Node: 20.12.1 - ~/.nvm/versions/node/v20.12.1/bin/node npm: 10.5.0 - ~/.nvm/versions/node/v20.12.1/bin/npm pnpm: 9.0.4 - /usr/local/bin/pnpm
  • Browsers: Chrome: 124.0.6367.61 Safari: 17.4.1
  • npmPackages: @auth/prisma-adapter: ^2.0.0 => 2.0.0 next: 14.2.2 => 14.2.2 next-auth: 5.0.0-beta.16 => 5.0.0-beta.16 react: ^18 => 18.2.0

Reproduction URL

https://github.com/gnasamx/my-app/blob/main/lib/auth.ts

Describe the issue

Doc says magic link will also add an entry in Account table. Link: https://authjs.dev/concepts/database-models#account

But Account has some problem. I'm using Resend provider. It's minimal setup (repo link is below). But I don't see a user entry in Account table. I can confirm that the User, Session, VerificationToken table entries are working correctly.

Screenshot 2024-04-20 at 10 49 28 PM

How to reproduce

  • Clone the repo
  • Update Resend api key in .env
  • Update Database Url in .env postgresql://username:password@localhost:5432/app
  • Run pnpm Prisma db push

Expected behavior

An entry (with type as "email" and provider as "Resend") should be added on successfully verifying the email sign in invitation link.

gnasamx avatar Apr 20 '24 17:04 gnasamx

After seeing your issue i checked my mongodb cluster and this is correct, All users that came through resend are not being added to the account collection.

tarun7singh avatar Apr 24 '24 23:04 tarun7singh

@gnasamx @tarun7singh If you only use email with Resend then the recording will only be made in the User table Account table is only for other providers like Google, Github, etc. If you sign in by email first and then use a Google account with the same email address, you will see a record in Account and this will automatically be linked to the one in User by user ID. This is what I understood with the documentation and after doing the test locally. Is this right?

mickasmt avatar Apr 25 '24 10:04 mickasmt

No. What you are talking is related to account linking (with same email) if I'm not wrong. Also I'm pretty sure, this was working a couple a days ago. I mean I have seen an entry in Account table with type as an email and provider as a Resend after successfully verification.

Also it is mentioned the docs that magic link will create an entry in Account table. I have attached a doc link in the first comment.

If I understood it correctly then this is part of code that runs on verify callback back for email type and related to account: https://github.com/nextauthjs/next-auth/blob/662e84f9a65eb0e74dc07e924aa15dfb37631f85/packages/core/src/lib/actions/callback/index.ts#L224

Let's see if someone knows/facing this issue.

gnasamx avatar Apr 25 '24 14:04 gnasamx

I am facing the same issue. Did you find a find a fix for this or identified the cause?

JesperSvensson00 avatar Jul 21 '24 11:07 JesperSvensson00

Sorry but no, I did not identified the cause. I decided not to use the magic link for a time being.

gnasamx avatar Jul 22 '24 11:07 gnasamx