verification databaseHooks is not triggering #1283

Closed
opened 2026-03-13 08:31:16 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @cesarve77 on GitHub (May 30, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

clone https://github.com/cesarve77/better-auth.git
install dependencies
run dev
go to http://localhost:3000/
register a new user
go to server console
clic in the url 'http://localhost:3000/api/auth/verify-email?token=xxxxxxx'

should trigger verification databaseHooks, appearing in the console the after and before logs, but is not

Current vs. Expected behavior

clicking in the verification email url 'http://localhost:3000/api/auth/verify-email?token=xxxxxxx' should trigger the verification databaseHooks

What version of Better Auth are you using?

1.2.8

Provide environment information

- MACOS
- Chome

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

Backend

Auth config (if applicable)

import {betterAuth} from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@/db"; // your drizzle instance
import * as z from "zod";

export const auth = betterAuth({
    emailVerification: {
        sendVerificationEmail: async ({ user, url, token }) => {
            console.log("sendVerificationEmail", { user, url, token });
        },
        sendOnSignUp: true,
        autoSignInAfterVerification: true,
        expiresIn: 3600 // 1 hour
    },

    databaseHooks: {
        verification: {
            update:{
                async before(verification, context)  {
                    console.log('update before verification', verification)
                    return true
                },
                async after(verification, context)  {
                    console.log('update after verification', verification)
                }
            },
            create: {
                async before(verification, context)  {
                    console.log('create before verification', verification)
                    return true

                },
                async after(verification, context) {
                    console.log('create after verification', verification)
                }
            }
        },   

    },
    database: drizzleAdapter(db, {
        provider: "sqlite", // or "mysql", "sqlite"

    }),
    emailAndPassword: {
        enabled: true
    },

    user: {
        additionalFields: {
            role: {
                type: "string",
                required: true,
                // defaultValue: "user",
                input: false, // don't allow user to set role
                validator: {
                    input: z.enum(["user", "admin"]),
                },
                returned: true,
            },
        }
    }
});

Additional context

No response

Originally created by @cesarve77 on GitHub (May 30, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce clone https://github.com/cesarve77/better-auth.git install dependencies run dev go to http://localhost:3000/ register a new user go to server console clic in the url 'http://localhost:3000/api/auth/verify-email?token=xxxxxxx' should trigger verification databaseHooks, appearing in the console the after and before logs, but is not ### Current vs. Expected behavior clicking in the verification email url 'http://localhost:3000/api/auth/verify-email?token=xxxxxxx' should trigger the verification databaseHooks ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash - MACOS - Chome ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import {betterAuth} from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@/db"; // your drizzle instance import * as z from "zod"; export const auth = betterAuth({ emailVerification: { sendVerificationEmail: async ({ user, url, token }) => { console.log("sendVerificationEmail", { user, url, token }); }, sendOnSignUp: true, autoSignInAfterVerification: true, expiresIn: 3600 // 1 hour }, databaseHooks: { verification: { update:{ async before(verification, context) { console.log('update before verification', verification) return true }, async after(verification, context) { console.log('update after verification', verification) } }, create: { async before(verification, context) { console.log('create before verification', verification) return true }, async after(verification, context) { console.log('create after verification', verification) } } }, }, database: drizzleAdapter(db, { provider: "sqlite", // or "mysql", "sqlite" }), emailAndPassword: { enabled: true }, user: { additionalFields: { role: { type: "string", required: true, // defaultValue: "user", input: false, // don't allow user to set role validator: { input: z.enum(["user", "admin"]), }, returned: true, }, } } }); ``` ### Additional context _No response_
Author
Owner

@Kinfe123 commented on GitHub (May 31, 2025):

The verification table is not directly involved in the email verification process. It's used for other purposes like OAuth state management and temporary verification states, but not for email verification.

@Kinfe123 commented on GitHub (May 31, 2025): The verification table is not directly involved in the email verification process. It's used for other purposes like OAuth state management and temporary verification states, but not for email verification.
Author
Owner

@cesarve77 commented on GitHub (May 31, 2025):

Is there any trigger to know when a user virified thier email?

Cesar Ramos
+61416930601
Gold Coast, Australia

El sáb, 31 may. 2025, 8:51 p. m., KinfeMichael Tariku <
@.***> escribió:

Kinfe123 left a comment (better-auth/better-auth#2840)
https://github.com/better-auth/better-auth/issues/2840#issuecomment-2925574703

The verification table is not directly involved in the email verification
process. It's used for other purposes like OAuth state management and
temporary verification states, but not for email verification.


Reply to this email directly, view it on GitHub
https://github.com/better-auth/better-auth/issues/2840#issuecomment-2925574703,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AA6JPJ57VEXSOF76F7J3AHL3BH23DAVCNFSM6AAAAAB6H6LRJ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSMRVGU3TINZQGM
.
You are receiving this because you authored the thread.Message ID:
@.***>

@cesarve77 commented on GitHub (May 31, 2025): Is there any trigger to know when a user virified thier email? Cesar Ramos +61416930601 Gold Coast, Australia El sáb, 31 may. 2025, 8:51 p. m., KinfeMichael Tariku < ***@***.***> escribió: > *Kinfe123* left a comment (better-auth/better-auth#2840) > <https://github.com/better-auth/better-auth/issues/2840#issuecomment-2925574703> > > The verification table is not directly involved in the email verification > process. It's used for other purposes like OAuth state management and > temporary verification states, but not for email verification. > > — > Reply to this email directly, view it on GitHub > <https://github.com/better-auth/better-auth/issues/2840#issuecomment-2925574703>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AA6JPJ57VEXSOF76F7J3AHL3BH23DAVCNFSM6AAAAAB6H6LRJ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSMRVGU3TINZQGM> > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> >
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1283