[GH-ISSUE #2349] ID number changing to a string #17790

Closed
opened 2026-04-15 16:05:35 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @jonnny013 on GitHub (Apr 18, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2349

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I am using postgres and the user ID is an integer. After running a recent update and updating
advanced: { database: { generateId: false, } },

The user ID integers are being returned as strings when logging in (tested with email and password) which is causing issues in other tables and parsers where user_id is being used.

Current vs. Expected behavior

When a user logs in, the user ID should return a number, not a string

What version of Better Auth are you using?

1.2.7

Provide environment information

Hand tested with:
- OS: Mac
- Browser: Chrome

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
  advanced: {
    database: {
      generateId: false,
    }
  },
});

Additional context

No response

Originally created by @jonnny013 on GitHub (Apr 18, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2349 Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I am using postgres and the user ID is an integer. After running a recent update and updating `advanced: { database: { generateId: false, } },` The user ID integers are being returned as strings when logging in (tested with email and password) which is causing issues in other tables and parsers where user_id is being used. ### Current vs. Expected behavior When a user logs in, the user ID should return a number, not a string ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash Hand tested with: - OS: Mac - Browser: Chrome ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, advanced: { database: { generateId: false, } }, }); ``` ### Additional context _No response_
GiteaMirror added the lockedwontfix labels 2026-04-15 16:05:35 -05:00
Author
Owner

@ping-maxwell commented on GitHub (Apr 20, 2025):

This is intentional. All existing code for BA has been built around the idea that id is a string, same with external code (such as libraries that utilize Better Auth).

This will remain a string.

<!-- gh-comment-id:2817112648 --> @ping-maxwell commented on GitHub (Apr 20, 2025): This is intentional. All existing code for BA has been built around the idea that `id` is a string, same with external code (such as libraries that utilize Better Auth). This will remain a string.
Author
Owner

@ping-maxwell commented on GitHub (Apr 20, 2025):

Also, are you using auto-incrementing number ids?

<!-- gh-comment-id:2817112787 --> @ping-maxwell commented on GitHub (Apr 20, 2025): Also, are you using auto-incrementing number ids?
Author
Owner

@ping-maxwell commented on GitHub (Apr 20, 2025):

I'm closing this for now.

<!-- gh-comment-id:2817113783 --> @ping-maxwell commented on GitHub (Apr 20, 2025): I'm closing this for now.
Author
Owner

@jonnny013 commented on GitHub (Apr 24, 2025):

Yes, I am using auto-incrementing IDs. Is there a workaround for that?

<!-- gh-comment-id:2826393196 --> @jonnny013 commented on GitHub (Apr 24, 2025): Yes, I am using auto-incrementing IDs. Is there a workaround for that?
Author
Owner

@ping-maxwell commented on GitHub (Apr 24, 2025):

@jonnny013 Make sure to set advanced.database.useNumberId as true, this allows the adapter to automatically convert the string data back to number before saving to your DB.

However, all data returned by Better-Auth for id will be a string, and there isn't a work-around.

<!-- gh-comment-id:2827599530 --> @ping-maxwell commented on GitHub (Apr 24, 2025): @jonnny013 Make sure to set `advanced.database.useNumberId` as `true`, this allows the adapter to automatically convert the string data back to number before saving to your DB. However, all data returned by Better-Auth for `id` will be a string, and there isn't a work-around.
Author
Owner

@jd-solanki commented on GitHub (Sep 18, 2025):

For the records: export type User = Omit<typeof auth.$Infer.Session.user, 'id'> & { id: number }

<!-- gh-comment-id:3308037810 --> @jd-solanki commented on GitHub (Sep 18, 2025): For the records: `export type User = Omit<typeof auth.$Infer.Session.user, 'id'> & { id: number }`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17790