Error with custom field mapping. whereClause id getting undefined value
I'm migrating from Auth0 to better-auth.
In my existing project users table called
UsersView
(don't ask). And the primary key is userId
(instead of just id
)
Here is my config:
The OTP code is generating succesfuly:
And here is the db record that I'm getting in verifications table: (see screenshot)
Now when I submit the code I'm getting an error
When I console log the whereClause, here is what I see.
Please advice
5 Replies
version "better-auth": "^1.2.3",
I think this is where my issue comes from
https://github.com/better-auth/better-auth/blob/f90581d7ab0493fb58d3c2654c326f6f28a684b3/packages/better-auth/src/plugins/email-otp/index.ts#L488
It tries to update user and set
But it fails because it getting user id from user.user.id instead of user.user.userId...
does the id can be mapped to userId in a simple fix or I'll have to add a new column to my db?

id can't be mapped to something else
@bekacru I've added
id
column as a primary key, and moved userId
column to be not nullable "alias". The login for existing user is now working as expected as it just fetching the existing user by email. The sign up flow however fails, because it can't populate userId
required field.
Refactoring the whole codebase form userId to id would be taugh. The only workaround that I can use is to somehow make better-auth create a new user with userId=id.
I was looking into the documentation for additional fields. Is there a way to somehow make better-auth populate userId with id?
This is my only blocker at the moment. I'm 99% close to ditch Auth0.
A Before Hook maybe?
Anyone looking for a solution, here is how it's done