How do I setup id when creating new users?
I am trying to use stripe plugin
2025-06-02T19:51:30.109Z WARN [Better Auth]: [Kysely Adapter] - You are trying to create a record with an id. This is not allowed as we handle id generation for you, unless you pass in the
forceAllowId
parameter. The id will be ignored.
Create method with id
being called at:
at createWithHooks (webpack-internal:///(rsc)/./node_modules/better-auth/dist/shared/better-auth.XjdOGtZf.mjs:78:85)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.createOAuthUser (webpack-internal:///(rsc)/./node_modules/better-auth/dist/shared/better-auth.XjdOGtZf.mjs:158:27)
at async handleOAuthUserInfo (webpack-internal:///(rsc)/./node_modules/better-auth/dist/shared/better-auth.Dvh-YFwT.mjs:1285:14)14 Replies
Have the same problem, did you manage to solve it?
Right now there isn't a way to generate an ID like this.
Your best bet if you really want a custom ID for users is to pass an id generator in your auth config via
advanced.database.generateId
@Ping I do need, cause I have to maintain backward compatibility with my DB. my user.id filed called user.userId, and I have to keep the
id
and userId
equal during user creation. Unless you can suggest any other way to do so.
For now, I had to downgrade the library to 1.2.3 version.
Here is my code:
Can you please advice?Opened a PR to support passing
id
.
You can track it here:
https://github.com/better-auth/better-auth/pull/3048GitHub
feat(database-hooks): Allow passing
id
in DB hook create
by pin...It's the same to using a custom idGenerator, except configurable by the database hook which would in theory provide more data.
A use-case is to generate the id based on user info in the use...
Thanks! I see it doesn't pass the tests
is there a way to implement something similar for organizations? A littile different, but basically I want to create a column based off the id, but the ID is not passed to the "before" db hook for the organization

Not right now, but once database hooks are supported across all tables, you should be able to achieve this using DB hooks.
ok
@Ping It seems like the user.id is not passed in the regular before create dbhook eaither.
Here is my code:
And here is the log of user that I'm getting:
Is there any way to get user.id in the database before hook?
When DB hooks are supported for all tables is when this will be supported, right now you can't
So there is no way for me to set a duplicated id for any other field in the table rn? Do you have an ETA when it will be supported?
@Ping
Not sure, it will definitely be after 1.3.
We need all adapters to use our
createAdapter
wrapper function in order for us to start work on features like this. Right now mongoDb adpater doesn't use it, and other community made ones are not either. It may take some time as we will need to add warnings to users for those who are using adapters which doesn't use createAdapter
and stuff to alert the adapter maintainers to update...Got you, thank you for the response. I'm now trying to use the after: hook