how to update the session
So I am quite new to better auth; earlier, next auth used to be my go-to solution, but it's getting rough. I am struggling to understand the designs of better auth. When I use getSession, the session is an object of session and user.
Now I want to extend the session object. Let's say I want to add orgSlug to the session. Where should I add it? On session.session or session.user?
According to the docs,
According to the docs,
Customizing Session Response
added a "newFiled" to session.user. Where should I add this, and more importantly, how?23 Replies
So, if I go according to the docs, let's add an orgSlug on session.user
If I go according to the docs
workaround for type interferences in custom session
I am loosing all my types customSessionthis is what the docs suggested

this is my code ss, the same goes with session. Both session and user are inferring as
unknown

if I remove options, it behaves normally

I am in sooo much pain 😢
back to customizing the session
wait a sec, I am getting pissed rn
there are two different ways to infer custom fields on auth-client??? whyyyyy


the first one is under typescript and he second one is under customizing session response
May I see where you defined
options
?
Most cases, the reason why the user
and session
become unknown
is because the auth config inferred the plugins
array as empty []
.
But you may have other stuff defined in options, 🤔
Both of them act differently, the first ss is to infer any additionalFields
or mapped fields
you may have defined in your auth config.
The second is purely for mapping the session & user by your customSession pluginfelt overwhelmed
hey @Ping I want help on session update. How do I update it
btw which to use?
I assume you mean you want the orgSlug in the session. Here's an example

In this case where you're just wanting the customSession inference, just use the
customSessionClient
.lemme try this

is this how it works?
options for aut.ts

this is what I am experiencing rn


the first ss is of the type error I am getting when I am trying to use
authclient.udpateUser to update the org slug
the second one are the logs,
You can't set that via updateUser.
You need to use your ORM to set this
so in better-auth you can't update the session ?
Yes.
Just use your ORM, that's updating the session.
😢
how to do it via orm
probaly like
I am using drizzle
with orm i am update it in db, but how to update it on client?
wait a sec, just found something
I can confirm that this works

i am able to update the session
@Ping this works for me :))
so what i did was
I updated the session on db
refetch on client