use `updateUser` in route handler
yo so ik u use
authClient
on client side
but if i want to Update User Information on server side (from a route handler) what do i do?
docs show
await authClient.updateUser({
image: "https://example.com/image.jpg",
name: "John Doe",
})
but idt i can use authClient and pass user info on a route handler
I want to set that value to a field the client cant see
my config:
user: {
additionalFields: {
// when user uploads / or edits raw data, it gets added to their user object
raw_data_mongo_ref_id: {
// (TODO: make sure this is updated when edited)
type: "string",
required: false,
default: "null",
input: false, // don't allow users to set this value
},
},
},
using mongo as my db18 Replies
Get session and then call auth.api.updateUser on the server
https://www.better-auth.com/docs/concepts/api
API | Better Auth
Better Auth API.
So can I not do it directly In my route handler?
The instantiation of the auth object
Or do I just import the connection I made in lib folder
Can not do what directly in the route handler ?
Ahh
https://www.better-auth.com/docs/basic-usage
Do you understand the basic usage of authClient and auth ?
Basic Usage | Better Auth
Getting started with Better Auth
You define your auth and authClient, on the server you can use auth.api, on client authClient
The server has equivalent functionality, only difference is that you need to pass some identifiers (often userId that you can get from the session) to update user data
Ah so I import my auth from the lib file right
Yes
For server
Alr ty
For client it’s from your e.g. auth-client.ts
Solution
And for server from your auth.ts
yes tysm
hey so im not able to update a field properly
Object literal may only specify known properties, and 'raw_data_mongo_ref_id' does not exist in type '{ body: Partial<Prettify<{} & {} & { name?: string | undefined; image?: string | null | undefined; }>>; method?: "POST" | undefined; query?: Record<string, any> | undefined; ... 6 more ...; path?: string | undefined; }'.ts(2353)
what im updating is an additional value to the schema
can i not do that with this method
do i need to go into db and change it
Hm you are right I also dont find a way to address the user id in the api.updateUser function
I looked up my codebase and found that I update user data (except for the password) using my prisma adapter myself
The password I update using auth.$context
im trying to just update an existing field. so would i go into the db and send a query?
using mongo
I have no experience about mongodb to be clear but yes you can just use your way of changing data in the DB
alr do i change the user table or accounts table?
Depends on what data you need to change ?
its an additional value i added to the schema in auth.ts