#Next-Auth email verification ?

33 messages · Page 1 of 1 (latest)

clever plank
#

Do anyone got a tutorial about how setup email verification (at sign-up with credentials) ? I dont know why isnt working :

providers: [
                ...previous code
        EmailProvider({
            from: process.env.EMAIL_FROM,
            sendVerificationRequest,
        
        })
    ],

And there is my resend code :

  params: SendVerificationRequestParams,
) => {
  let { identifier: email, url, provider: { from } } = params;
  try {
    const resend = new Resend( process.env.RESEND_API_KEY! );
    await resend.emails.send({
      from: from,
      to: email,
      subject: 'Login Link to your Account',
      html: '<p>Click the magic link below to sign in to your account:</p>\
             <p><a href="' + url + '"><b>Sign in</b></a></p>',
    });
    console.log('Email sent to ' + email + ' with the magic link: ' + url)
  } catch (error) {
    console.log({ error });
  }
};```
livid galleonBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

hexed stump
clever plank
# hexed stump The email provider is meant to provide a one-time sign in using a magic link. Th...

Ive seen this page, but when I signup a user, not token is generated and no email is sent. I also have an error :
https://next-auth.js.org/errors#missing_adapter_methods_error Required adapter methods were missing: createVerificationToken, useVerificationToken, getUserByEmail MissingAdapterMethods [MissingAdapterMethodsError]: Required adapter methods were missing: createVerificationToken, useVerificationToken, getUserByEmail

Btw Im using Postgres and Prisma

#

The only way to make thing work is by make my own call to send email with resend, and generate my own token with uuid, etc... But I guess its better to use the default setup from NextAuth

hexed stump
clever plank
#

There is something weird, the doc fro Prisma adapter say to create a table like this :
`model VerificationRequest {
id String @id @default(cuid())
identifier String
token String @unique
expires DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@unique([identifier, token])
}`

But every tutorial are using the name VerificationToken instead. Right now, Ive go some weird use with login, like if I got the wrong email/password Im having this page :

#

Same with the route/api/auth/new-verification :
{"message":"There is a problem with the server configuration. Check the server logs for more information."}

hexed stump
#

What do the server logs say?

#

This is the logs of your dev server itself

clever plank
# hexed stump This is the logs of your dev server itself

Well I guess this :
https://next-auth.js.org/errors#missing_adapter_methods_error Required adapter methods were missing: createVerificationToken, useVerificationToken, getUserByEmail MissingAdapterMethods [MissingAdapterMethodsError]: Required adapter methods were missing: createVerificationToken, useVerificationToken, getUserByEmail

But its weird because I follow a tutorial and everything work perfectly for him, and he got the name of the table VerificationToken instead of VerificationRequest

hexed stump
#

Use verification token then

#
model VerificationToken {
  identifier String
  token      String   @unique
  expires    DateTime

  @@unique([identifier, token])
}
#

Also make sure your prisma adapter is setup

clever plank
#

BEcause right now Im following a tutorial where I have to make my own token, but I dont wanna make something wrong so if there is a builtin functionality for that it could be more stable and easy for me

hexed stump
clever plank
hexed stump
#

Well yes, email provider is for magic links

#

IIRC

clever plank
hexed stump
#

Honestly im not that experienced in NextAuth, however If you want Credentials Login(email/password) then you'll need to handle the email verification yourself

clever plank
hexed stump
#

Nah its fine

clever plank
# hexed stump Nah its fine

Btw I kinda lost with all the notion of server side and client side. Because I need to use React Query for all my state in the app, but some tutorial make update in db with server action, others with api routes, etc... Which one should I use. Api route seems more clean for me but use fetch every time is kinda boring

#

I plan to dev after a react native app, so maybe use API route is better no ? Because server action arent accessible from public right ?

hexed stump
#

So thats something to look into

hexed stump
#

I saw something about being able to call them using the POST action.

clever plank