[GH-ISSUE #1765] The field identifier in the table verification should be indexed #8906

Closed
opened 2026-04-13 04:09:14 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @saulogt on GitHub (Mar 11, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1765

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I created the schema using npx @better-auth/cli generate and in the schema generated, the table verification is not indexed properly.

I wonder if it even should be unique!

Current vs. Expected behavior

Expected:

export const verification = pgTable(
  "verification",
  {
    id: text("id").primaryKey(),
    identifier: text("identifier").notNull(), // or .unique() !!!
    value: text("value").notNull(),
    expiresAt: timestamp("expires_at").notNull(),
    createdAt: timestamp("created_at"),
    updatedAt: timestamp("updated_at"),
  },
  (table) => [
    index("idx_verification_identifier").using("btree", table.identifier.asc()),
  ],
);

Current:

export const verification = pgTable("verification", {
  id: text("id").primaryKey(),
  identifier: text("identifier").notNull(),
  value: text("value").notNull(),
  expiresAt: timestamp("expires_at").notNull(),
  createdAt: timestamp("created_at"),
  updatedAt: timestamp("updated_at"),
});

What version of Better Auth are you using?

1.1.2

Provide environment information

- Macos

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"

export const auth = betterAuth(
  {
    emailVerification: {
      sendVerificationEmail: async ({ user, url, token }, request) => {
        await sendEmailVerification(user.email, url, "en");
      },
    },
    database: drizzleAdapter(db2, {
      provider: "pg",
      schema,
    }),
    emailAndPassword: {
      enabled: true,
      sendResetPassword: async (data, request) => {
        sendPasswordReset(data.user.email, data.url, "en");
      },
    },
    socialProviders: {
      google: {
        clientId: process.env.GOOGLE_CLIENT_ID!,
        clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
      },
    },
    plugins: [organization({}), nextCookies()], 

  })

Additional context

  • Drizzle
  • pg
  • NextJS
  • npx @better-auth/cli -V => 1.1.2
Originally created by @saulogt on GitHub (Mar 11, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1765 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I created the schema using `npx @better-auth/cli generate` and in the schema generated, the table verification is not indexed properly. I wonder if it even should be unique! ### Current vs. Expected behavior ## Expected: ```js export const verification = pgTable( "verification", { id: text("id").primaryKey(), identifier: text("identifier").notNull(), // or .unique() !!! value: text("value").notNull(), expiresAt: timestamp("expires_at").notNull(), createdAt: timestamp("created_at"), updatedAt: timestamp("updated_at"), }, (table) => [ index("idx_verification_identifier").using("btree", table.identifier.asc()), ], ); ``` ## Current: ```js export const verification = pgTable("verification", { id: text("id").primaryKey(), identifier: text("identifier").notNull(), value: text("value").notNull(), expiresAt: timestamp("expires_at").notNull(), createdAt: timestamp("created_at"), updatedAt: timestamp("updated_at"), }); ``` ### What version of Better Auth are you using? 1.1.2 ### Provide environment information ```bash - Macos ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth( { emailVerification: { sendVerificationEmail: async ({ user, url, token }, request) => { await sendEmailVerification(user.email, url, "en"); }, }, database: drizzleAdapter(db2, { provider: "pg", schema, }), emailAndPassword: { enabled: true, sendResetPassword: async (data, request) => { sendPasswordReset(data.user.email, data.url, "en"); }, }, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID!, clientSecret: process.env.GOOGLE_CLIENT_SECRET!, }, }, plugins: [organization({}), nextCookies()], }) ``` ### Additional context - Drizzle - pg - NextJS - npx @better-auth/cli -V => 1.1.2
GiteaMirror added the lockedenhancement labels 2026-04-13 04:09:14 -05:00
Author
Owner

@moshetanzer commented on GitHub (Mar 25, 2025):

Hey,

Thanks for this.

Yes Better auth does suggest indexing identifier and quite a few more fields. See https://www.better-auth.com/docs/guides/optimizing-for-performance#database-optimizations

<!-- gh-comment-id:2750487383 --> @moshetanzer commented on GitHub (Mar 25, 2025): Hey, Thanks for this. Yes Better auth does suggest indexing `identifier` and quite a few more fields. See https://www.better-auth.com/docs/guides/optimizing-for-performance#database-optimizations
Author
Owner

@dosubot[bot] commented on GitHub (Aug 2, 2025):

Hi, @saulogt. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that the identifier field in the verification table schema generated by Better Auth is not indexed.
  • You suggested adding a btree index or making it unique for better performance.
  • The maintainer confirmed that Better Auth does recommend indexing identifier and other fields.
  • Official documentation on database optimizations was referenced to address your concern.
  • The issue was effectively resolved with this clarification.

Next Steps:

  • Please let me know if this issue is still relevant to the latest version of better-auth by commenting here.
  • Otherwise, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3146583645 --> @dosubot[bot] commented on GitHub (Aug 2, 2025): Hi, @saulogt. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that the `identifier` field in the `verification` table schema generated by Better Auth is not indexed. - You suggested adding a btree index or making it unique for better performance. - The maintainer confirmed that Better Auth does recommend indexing `identifier` and other fields. - Official documentation on database optimizations was referenced to address your concern. - The issue was effectively resolved with this clarification. **Next Steps:** - Please let me know if this issue is still relevant to the latest version of better-auth by commenting here. - Otherwise, this issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8906