[GH-ISSUE #996] Email Verification isn't logging the user in #8541

Closed
opened 2026-04-13 03:38:48 -05:00 by GiteaMirror · 10 comments
Owner

Originally created by @daveycodez on GitHub (Dec 23, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/996

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Click an email verification link, and you have to enter the email and password again.

Current vs. Expected behavior

Email Verification link should act like a magic link and log the user in

What version of Better Auth are you using?

1.1.2

Provide environment information

Nextjs

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)

No response

Additional context

No response

Originally created by @daveycodez on GitHub (Dec 23, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/996 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Click an email verification link, and you have to enter the email and password again. ### Current vs. Expected behavior Email Verification link should act like a magic link and log the user in ### What version of Better Auth are you using? 1.1.2 ### Provide environment information ```bash Nextjs ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) _No response_ ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 03:38:48 -05:00
Author
Owner

@Bekacru commented on GitHub (Dec 23, 2024):

you need to set emailVerification.autoSignInAfterVerification to sign in after verification.

<!-- gh-comment-id:2559358119 --> @Bekacru commented on GitHub (Dec 23, 2024): you need to set `emailVerification.autoSignInAfterVerification` to sign in after verification.
Author
Owner

@daveycodez commented on GitHub (Dec 23, 2024):

Hmm I tried that option and it doesn't seem to be working. I am using anonymous users as well so maybe that is affecting it somehow?

    emailAndPassword: { enabled: true, requireEmailVerification: true },
    emailVerification: {
        sendVerificationEmail: async ({ user, url, token }, request) => {
            await resend.emails.send({
                from: "NEW-TECH <noreply@auth.newtech.dev>",
                to: user.email,
                subject: "Verify your email address",
                react: EmailTemplate({ preview: "Verify Email", content: "Click the button below to verify your email.", action: "Vefify Email", confirmationUrl: url })
            })
        },
        autoSignInAfterVerification: true,
        sendOnSignUp: true
    },
<!-- gh-comment-id:2559365835 --> @daveycodez commented on GitHub (Dec 23, 2024): Hmm I tried that option and it doesn't seem to be working. I am using anonymous users as well so maybe that is affecting it somehow? ```ts emailAndPassword: { enabled: true, requireEmailVerification: true }, emailVerification: { sendVerificationEmail: async ({ user, url, token }, request) => { await resend.emails.send({ from: "NEW-TECH <noreply@auth.newtech.dev>", to: user.email, subject: "Verify your email address", react: EmailTemplate({ preview: "Verify Email", content: "Click the button below to verify your email.", action: "Vefify Email", confirmationUrl: url }) }) }, autoSignInAfterVerification: true, sendOnSignUp: true }, ```
Author
Owner

@daveycodez commented on GitHub (Dec 23, 2024):

Okay I've verified that it is not working if you are currently logged in as an anonymous user, it should trigger the accounts merging like a normal login or sign up. Magic Link isn't having this issue.

<!-- gh-comment-id:2559400186 --> @daveycodez commented on GitHub (Dec 23, 2024): Okay I've verified that it is not working if you are currently logged in as an anonymous user, it should trigger the accounts merging like a normal login or sign up. Magic Link isn't having this issue.
Author
Owner

@Bekacru commented on GitHub (Dec 23, 2024):

that is cause it only applies if there is no active session at the time of verification. Verification isn't exactly a magic link or a way of signing in, so it doesn't override the current session or link an existing anonymous account upon verification.

<!-- gh-comment-id:2559644227 --> @Bekacru commented on GitHub (Dec 23, 2024): that is cause it only applies if there is no active session at the time of verification. Verification isn't exactly a magic link or a way of signing in, so it doesn't override the current session or link an existing anonymous account upon verification.
Author
Owner

@daveycodez commented on GitHub (Dec 23, 2024):

Need a way for email verification to also function as a magic link, or to just have the email verification trigger send the magic link instead. Otherwise this makes the anonymous users feature unusable

<!-- gh-comment-id:2560115491 --> @daveycodez commented on GitHub (Dec 23, 2024): Need a way for email verification to also function as a magic link, or to just have the email verification trigger send the magic link instead. Otherwise this makes the anonymous users feature unusable
Author
Owner

@Bekacru commented on GitHub (Dec 23, 2024):

hmm why not send them a magic link?

<!-- gh-comment-id:2560118756 --> @Bekacru commented on GitHub (Dec 23, 2024): hmm why not send them a magic link?
Author
Owner

@daveycodez commented on GitHub (Dec 23, 2024):

Well it still needs to require email verification on signup, so signup with password needs to return a null token

<!-- gh-comment-id:2560122140 --> @daveycodez commented on GitHub (Dec 23, 2024): Well it still needs to require email verification on signup, so signup with password needs to return a null token
Author
Owner

@Bekacru commented on GitHub (Dec 23, 2024):

yeah actually you're right. It make sense to log them in on anonymous case. if verification is required it'd be a blocker.

<!-- gh-comment-id:2560125659 --> @Bekacru commented on GitHub (Dec 23, 2024): yeah actually you're right. It make sense to log them in on anonymous case. if verification is required it'd be a blocker.
Author
Owner

@Bekacru commented on GitHub (Dec 23, 2024):

we'll generate new session if the email don't match on verification

<!-- gh-comment-id:2560126286 --> @Bekacru commented on GitHub (Dec 23, 2024): we'll generate new session if the email don't match on verification
Author
Owner

@daveycodez commented on GitHub (Dec 23, 2024):

Yea also to note, Magic Link isn't working if the email isn't verified and requireVerification is true. Magic Link should verify the email of an unverified email account on click. Magic Link & Email Verification function should be pretty much identical except for the text written in the email

<!-- gh-comment-id:2560127621 --> @daveycodez commented on GitHub (Dec 23, 2024): Yea also to note, Magic Link isn't working if the email isn't verified and requireVerification is true. Magic Link should verify the email of an unverified email account on click. Magic Link & Email Verification function should be pretty much identical except for the text written in the email
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8541