Discussion: Exchange default ID generation from random to something like UUID, NanoID, ulid, etc? #707

Closed
opened 2026-03-13 08:01:07 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @matthiasfeist on GitHub (Feb 19, 2025).

As far as I can see, better-auth currently has its own implementation to create random IDs for DB entries.

I was wondering if it might be good to move towards a different implementation like https://github.com/ulid/javascript for example.

Any opinions? Maybe there was a particular reason why going full custom on the ID generation was chosen?

Originally created by @matthiasfeist on GitHub (Feb 19, 2025). As far as I can see, better-auth currently has its own implementation to create random IDs for DB entries. I was wondering if it might be good to move towards a different implementation like https://github.com/ulid/javascript for example. Any opinions? Maybe there was a particular reason why going full custom on the ID generation was chosen?
Author
Owner

@Bekacru commented on GitHub (Feb 19, 2025):

We previously used nanoid but wanted a more neutral approach to leave the option for users to change it. The current implementation relies on crypto.getRandomValues, but we actually plan to default to db generated IDs in the near future.

@Bekacru commented on GitHub (Feb 19, 2025): We previously used nanoid but wanted a more neutral approach to leave the option for users to change it. The current implementation relies on `crypto.getRandomValues`, but we actually plan to default to db generated IDs in the near future.
Author
Owner

@matthiasfeist commented on GitHub (Feb 19, 2025):

Ah perfect! DB generated values are ultimately what I would want to use as well.
Is there a branch och something that I could contribute to? Or any other help you might want on this?

@matthiasfeist commented on GitHub (Feb 19, 2025): Ah perfect! DB generated values are ultimately what I would want to use as well. Is there a branch och something that I could contribute to? Or any other help you might want on this?
Author
Owner

@Bekacru commented on GitHub (Feb 20, 2025):

We already support db generated values by simply setting advanced.generateId to false. The only required change is making generateId: false the default. However, since this is somewhat of a breaking change, we're waiting for the right time to implement it and evaluating whether there are any reasons to keep generated IDs as the default, as we do now.

@Bekacru commented on GitHub (Feb 20, 2025): We already support db generated values by simply setting `advanced.generateId` to `false`. The only required change is making `generateId: false` the default. However, since this is somewhat of a breaking change, we're waiting for the right time to implement it and evaluating whether there are any reasons to keep generated IDs as the default, as we do now.
Author
Owner

@matthiasfeist commented on GitHub (Feb 20, 2025):

awesome. makes sense

@matthiasfeist commented on GitHub (Feb 20, 2025): awesome. makes sense
Author
Owner

@theinfinit commented on GitHub (Feb 24, 2025):

We already support db generated values by simply setting advanced.generateId to false.

Just tried it out. Changing generateId to false results in:

  • a NOT NULL constraint failed errors for existing and new DBs,
  • users being created without id, instead of being auto-incremented by DB (maybe ID it's explicitly set to NULL in the query?).
    • This results in error: Failed to create user SqliteError: NOT NULL constraint failed: user.id

Tested with 1.2.0-beta.16 npm package.

@theinfinit commented on GitHub (Feb 24, 2025): > We already support db generated values by simply setting `advanced.generateId` to `false`. Just tried it out. Changing `generateId` to `false` results in: - a `NOT NULL constraint failed` errors for existing and new DBs, - users being created without `id`, instead of being auto-incremented by DB (maybe ID it's explicitly set to NULL in the query?). - This results in error: `Failed to create user SqliteError: NOT NULL constraint failed: user.id` Tested with `1.2.0-beta.16` npm package.
Author
Owner

@dosubot[bot] commented on GitHub (Jun 14, 2025):

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

Issue Summary:

  • The issue proposes changing the default ID generation method to standardized libraries like UUID, NanoID, or ULID.
  • Current implementation uses crypto.getRandomValues, with an option to use database-generated IDs by setting advanced.generateId to false.
  • User theinfinit reported errors when setting generateId to false, such as NOT NULL constraint failed and users being created without IDs in version 1.2.0-beta.16.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the better-auth repository. If so, you can keep the discussion open by commenting on this issue.
  • Otherwise, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jun 14, 2025): Hi, @matthiasfeist. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - The issue proposes changing the default ID generation method to standardized libraries like UUID, NanoID, or ULID. - Current implementation uses `crypto.getRandomValues`, with an option to use database-generated IDs by setting `advanced.generateId` to `false`. - User theinfinit reported errors when setting `generateId` to `false`, such as `NOT NULL constraint failed` and users being created without IDs in version `1.2.0-beta.16`. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the better-auth repository. If so, you can keep the discussion open by commenting on this issue. - 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#707