How to update additionalFields of user?
I found this in the docs https://www.better-auth.com/docs/plugins/username#update-username and I can see in the
update-user.ts file that there is something with additional fields but I can't figure out how to access them.Username | Better Auth
Username plugin
13 Replies
you want to add additional fields to users?
My user already has additional fields. But I want to know how to use the updateUser function to update those fields. Because now I can only update the username and email
Ah for your own fields I think you'd need to make your own endpoints for that, but I'm not 100% sure
I have read the updateUser function of Better Auth code, you can not update email field.
And but if you want to update the additional fields, just need to pass them in request body. I just tested.
Eg: if your
user table has a columnage, then request body would be: {"age": 125, "username": "abcxyzporn"}
But if you have a separate table to manage those additional fields, then you can either do it like The Untraceable suggested, or can use databaseHooks -> user -> update -> before/afterThank you. I will try it
I have tried the client and server variant of it and I get Errors even when I am trying to update just the name.
ERROR [Better Auth]: ReplyError [ReplyError: ERR value is not an integer or out of range] {
command: [Object]
}
and the server version:
[Error [APIError]: ] {
status: 'UNAUTHORIZED',
body: undefined,
headers: {},
statusCode: 401,
digest: '223797055'
}
but the user is signed inWhat Better Auth version and database are you using?
For the server code, I noticed that you’re not passing the headers
Eg: Using Hono fw
Error: [ReplyError: ERR value is not an integer or out of range] {
command: [Object],
digest: '3363862555'
}
I am using Redis as SecondaryStorage, Postgres with Drizzle, CookieCache and "better-auth": "^1.3.7"
To resolve this, upgrade to the latest version of better-auth v1.3.13
I did upgrade but the error is still the same. Even deleted node modules.
If I log my secondary storage the
ttl is a float 520661.312. But how is this possible?
Oh sorry. I debugged your issue from the source code on GitHub and saw that this bug has already been fixed. It seems that the Better Auth team hasn’t released the latest version yet.
Don’t worry, this bug will likely be fixed in the next release, I hope 😁 .
Which file did you debug?
internal-adapter.ts
At line 57
Thank you.