# Better Auth Bug Report: Email Verification Not Creating Database Records ## Summary Better Auth is successfully sending verification emails and the verification flow works end-to-end, but **no verification records are being created in the database**. This prevents database hooks from firing and makes it impossible to implement custom logic based on email verification events. ## Environment - **Better Auth Version**: 1.2.10 - **Database**: PostgreSQL (Neon) - **ORM**: Prisma 6.10.1 - **Adapter**: Prisma Adapter - **Plugins**: nextCookies() only ## Expected Behavior According to Better Auth documentation: 1. When `sendVerificationEmail` is called, a verification record should be created in the database 2. The `databaseHooks.verification.create.after` hook should fire 3. Verification records should be visible in the verification table ## Actual Behavior 1. ✅ `sendVerificationEmail` function is called successfully 2. ✅ Verification emails are sent and received 3. ✅ Email verification links work and users can verify their emails 4. ❌ **No records are created in the verification table** 5. ❌ `databaseHooks.verification.create.after` never fires ## Database Schema ### Current Verification Table (Prisma) ```prisma model Verification { id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid identifier String value String expiresAt DateTime createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@map("verification") } ``` ### Better Auth Configuration ```typescript export const auth = betterAuth({ database: prismaAdapter(db), user: { modelName: 'User', }, advanced: { database: { generateId: false, // Using database-generated UUIDs }, }, emailVerification: { sendVerificationEmail: async ({ user, url, token }, _request) => { // This function IS being called successfully await sendEmail( user.email, 'Verify your email address', `
Hello ${user.name},
Please verify your email address by clicking the link below:
Verify Email ` ); }, sendOnSignUp: true, autoSignInAfterVerification: true, expiresIn: 3600, }, databaseHooks: { verification: { create: { after: async (verification, _ctx) => { // This hook NEVER fires console.log('Verification created', verification); }, }, }, }, }); ``` ## Debugging Evidence ### 1. Email Function is Called The `sendVerificationEmail` function logs show it's being called with correct parameters: ``` ✅ user: { id: "...", email: "user@example.com", ... } ✅ url: "http://localhost:3000/api/auth/verify-email?token=..." ✅ token: "eyJhbGciOiJIUzI1NiJ9..." ``` ### 2. Database Table is Empty ```sql SELECT COUNT(*) FROM verification; -- Result: 0 (always empty, even during active verification flow) ``` ### 3. Hook Never Fires The `databaseHooks.verification.create.after` hook never executes, confirming no database records are being created. ### 4. Schema Matches Documentation Our verification table schema matches the Better Auth documentation exactly: - ✅ All required fields present - ✅ Correct field types - ✅ Proper table mapping ## Additional Context ### Schema Generation When running `npx @better-auth/cli generate`, Better Auth generates this exact schema: ```prisma model Verification { id String @id identifier String value String expiresAt DateTime createdAt DateTime? updatedAt DateTime? @@map("verification") } ``` ### Other Tables Work Fine - ✅ User records are created successfully - ✅ Session records are created successfully - ✅ Account records are created successfully - ❌ **Only verification table remains empty** ## Hypothesis Better Auth appears to be using a stateless verification mechanism (possibly JWT tokens) instead of database storage for email verification, despite the documentation indicating database records should be created. ## Questions for Better Auth Team 1. Is email verification supposed to create database records? 2. Are there specific configuration requirements for database-backed verification? 3. Is there a difference between stateless vs database verification modes? 4. Should `databaseHooks.verification.create.after` fire for email verification? --- **Note**: This issue prevents implementing features that depend on verification events, such as triggering automated processes when users verify their email addresses.