[GH-ISSUE #5807] Map custom id field names #10355

Open
opened 2026-04-13 06:26:07 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @mfrancis107 on GitHub (Nov 6, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5807

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

It's our best practice to use ids such as tableNameId instead of just id.

Better auth allows for renaming all fields except the id fields.

We hack around this by having duplicated drizzle schema definitions just to satisfy better auth.

Describe the solution you'd like

export const auth = betterAuth({
  baseURL: process.env.BETTER_AUTH_URL,
  user: {
    fields: {
      id: text("user_id")
    }
  }
});

If we could map id field also like this.

Describe alternatives you've considered

Right now we include a seperately defined db schema

like so:

export const baseSchema = {
  user: sqliteTable("user", {
    id: text("user_id")
      .primaryKey()
      .$defaultFn(() => `u-${ulid()}`),
    name: text("name").notNull(),
    email: text("email").notNull().unique(),
    emailVerified: integer("email_verified", { mode: "boolean" }).notNull(),
    image: text("image"),
    role: text("role").default("user"),
    banned: integer("banned", { mode: "boolean" }).default(false),
    banReason: text("ban_reason"),
    banExpires: integer("ban_expires", { mode: "timestamp" }),
    createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
    updatedAt: integer("updated_at", { mode: "timestamp" }).notNull(),
  }),

that is only used for the better auth config. So essentially we have duplicate schema definitions for better auth related tables.

Additional context

No response

Originally created by @mfrancis107 on GitHub (Nov 6, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5807 Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [ ] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. It's our best practice to use ids such as tableNameId instead of just id. Better auth allows for renaming all fields except the id fields. We hack around this by having duplicated drizzle schema definitions just to satisfy better auth. ### Describe the solution you'd like ```ts export const auth = betterAuth({ baseURL: process.env.BETTER_AUTH_URL, user: { fields: { id: text("user_id") } } }); ``` If we could map id field also like this. ### Describe alternatives you've considered Right now we include a seperately defined db schema like so: ```ts export const baseSchema = { user: sqliteTable("user", { id: text("user_id") .primaryKey() .$defaultFn(() => `u-${ulid()}`), name: text("name").notNull(), email: text("email").notNull().unique(), emailVerified: integer("email_verified", { mode: "boolean" }).notNull(), image: text("image"), role: text("role").default("user"), banned: integer("banned", { mode: "boolean" }).default(false), banReason: text("ban_reason"), banExpires: integer("ban_expires", { mode: "timestamp" }), createdAt: integer("created_at", { mode: "timestamp" }).notNull(), updatedAt: integer("updated_at", { mode: "timestamp" }).notNull(), }), ``` that is only used for the better auth config. So essentially we have duplicate schema definitions for better auth related tables. ### Additional context _No response_
GiteaMirror added the database label 2026-04-13 06:26:07 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 6, 2025):

Hi there, thanks for opening this issue! Currently, Better Auth supports renaming all fields in the schema except for the id fields, so you’re having to duplicate your schema definitions as a workaround. We understand that mapping custom id field names like tableNameId would streamline your development process, and this feature request is on our radar. In the meantime, using your separate database schema with the custom id names is the recommended approach.

Would you like to share more details on how you’re using the custom ids so our team can better prioritize this feature? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3498033280 --> @better-auth-agent[bot] commented on GitHub (Nov 6, 2025): Hi there, thanks for opening this issue! Currently, Better Auth supports renaming all fields in the schema except for the id fields, so you’re having to duplicate your schema definitions as a workaround. We understand that mapping custom id field names like tableNameId would streamline your development process, and this feature request is on our radar. In the meantime, using your separate database schema with the custom id names is the recommended approach. Would you like to share more details on how you’re using the custom ids so our team can better prioritize this feature? Tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@nick-kang commented on GitHub (Nov 7, 2025):

We're also looking for this feature. Was asked here previously - https://www.answeroverflow.com/m/1359421010998198413

<!-- gh-comment-id:3500602479 --> @nick-kang commented on GitHub (Nov 7, 2025): We're also looking for this feature. Was asked here previously - https://www.answeroverflow.com/m/1359421010998198413
Author
Owner

@nick-kang commented on GitHub (Nov 7, 2025):

We were able to get custom id field names working by creating a view for each of the better-auth tables and using an alias.

Example for the user table:

CREATE VIEW user_view 
  WITH (security_barrier, check_option = 'cascaded')
  AS
    SELECT user_id as id
    , email_verified
    , name
    , email
    , image
    , role
    , banned
    , ban_reason
    , ban_expires
    , created_at
    , updated_at
    FROM user;
<!-- gh-comment-id:3501125661 --> @nick-kang commented on GitHub (Nov 7, 2025): We were able to get custom id field names working by creating a view for each of the better-auth tables and using an alias. Example for the `user` table: ```sql CREATE VIEW user_view WITH (security_barrier, check_option = 'cascaded') AS SELECT user_id as id , email_verified , name , email , image , role , banned , ban_reason , ban_expires , created_at , updated_at FROM user; ```
Author
Owner

@rovertrack commented on GitHub (Nov 7, 2025):

is it problematic with only users id or other tables too?

<!-- gh-comment-id:3502460786 --> @rovertrack commented on GitHub (Nov 7, 2025): is it problematic with only users id or other tables too?
Author
Owner

@mfrancis107 commented on GitHub (Nov 10, 2025):

We need it for all tables.

<!-- gh-comment-id:3513673635 --> @mfrancis107 commented on GitHub (Nov 10, 2025): We need it for all tables.
Author
Owner

@himself65 commented on GitHub (Nov 13, 2025):

/cc @ping-maxwell

<!-- gh-comment-id:3529787223 --> @himself65 commented on GitHub (Nov 13, 2025): /cc @ping-maxwell
Author
Owner

@Ridhim-RR commented on GitHub (Nov 15, 2025):

I try to implement this for user, session, and account tables but this leads to lot of changes/conflictions in the test cases.So decided to withdraw the PR.

<!-- gh-comment-id:3536419454 --> @Ridhim-RR commented on GitHub (Nov 15, 2025): I try to implement this for user, session, and account tables but this leads to lot of changes/conflictions in the test cases.So decided to withdraw the PR.
Author
Owner

@insano70 commented on GitHub (Dec 19, 2025):

Tried to use better-auth for the first time on a new project and ran straight into this issue. Please don't try to inflict your database column names on others, let us pick our own.

<!-- gh-comment-id:3675412182 --> @insano70 commented on GitHub (Dec 19, 2025): Tried to use better-auth for the first time on a new project and ran straight into this issue. Please don't try to inflict your database column names on others, let us pick our own.
Author
Owner

@nickhod commented on GitHub (Mar 3, 2026):

This limitation isn't clear from the docs
https://better-auth.com/docs/concepts/database#custom-table-names

Ideally the id fields would be customizeable, but if this isn't possible an error should be thrown when its attempted. Wasted several hours trying to figure this out before finding this issue.

<!-- gh-comment-id:3991328834 --> @nickhod commented on GitHub (Mar 3, 2026): This limitation isn't clear from the docs https://better-auth.com/docs/concepts/database#custom-table-names Ideally the id fields would be customizeable, but if this isn't possible an error should be thrown when its attempted. Wasted several hours trying to figure this out before finding this issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10355