Allow us to mutate the session on the client side without making any other call like getSession() #2267
Replies: 1 comment 1 reply
-
Hi, and thanks for opening this. So when the session value changes and is being persisted either in a database or in the HttpOnly session cookie as JWT, the value can only be written server-side, so a trip to the server is inevitable. But I think we could expose a new function, something like const { data: session, update } = useSession()
...
const handleUpdate = async () => {
update((prev) => {...prev: foo: "new session value"})
}
I am currently refactoring the |
Beta Was this translation helpful? Give feedback.
-
Summary 💭
Include a
setState
to mutate thesession
state when using theuseSession()
hook.Description 📓
In my app, I'm trying to build a settings page for profiles, like changing the display name etc, but I found that after changing the display name (name in database has been changed), the
session
state inuseSession()
stayed the same.So, I was trying to find a way to mutate the session object of the current user and stumbled upon
getSession()
which (correct me if I'm wrong) is suppose to get a new session and replace it with the current one but according to thisissue
it doe not work as intended.I was looking at the source code and thought wouldn't it be easier to just allow us to mutate the session state directly? (or are there security concerns I'm not aware of? In which case, it would be interesting to know). Looking at the code, it should be pretty easy to implement.
An advantage when compared to
getSession()
would obviously be that 1 less call needs to be made to the database, but again, I'm not sure if I am glossing over any security concerns etcBeta Was this translation helpful? Give feedback.
All reactions