How to update the user session on server side
Unanswered
Eyebrowed Thrush posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Eyebrowed ThrushOP
I am working with server actions in the nextjs. Lets suppose user had updated his name and action is completed using the server action. Then how i can update the user session in the same action instead of calling the auth update which refethes the data from the server again
I am using the next auth (beta version) sorry I forgot to add this in question.
And I think they don't provide a way to update session in server side
I am using the next auth (beta version) sorry I forgot to add this in question.
And I think they don't provide a way to update session in server side
14 Replies
![Avatar](https://cdn.discordapp.com/avatars/108266952383807488/6861c0c2dea6601d7354108578ec86d0.webp?size=256)
MikeTheTechLead
Look into using something like next-auth. In that library, the session can be set up as being a jwt token, which gets sent to the client via a cookie.
So essentially when you update the session on the serverside, you update that cookie, which then gets sent to the client via a call
So essentially when you update the session on the serverside, you update that cookie, which then gets sent to the client via a call
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Tan
You need to add a middleware for that
In the middleware you request your api get new sessions and set new cookies from the middleware
![Avatar](https://cdn.discordapp.com/avatars/108266952383807488/6861c0c2dea6601d7354108578ec86d0.webp?size=256)
MikeTheTechLead
You can also set cookies inside server action btw
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Tan
Yup and it also can be called from middleware
![Avatar](https://cdn.discordapp.com/avatars/108266952383807488/6861c0c2dea6601d7354108578ec86d0.webp?size=256)
MikeTheTechLead
https://nextjs.org/docs/app/api-reference/functions/cookies @Eyebrowed Thrush there's a little bit information here about it
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Eyebrowed ThrushOP
I am using the next auth (beta version) sorry I forgot to add this in question.
And I think they don't provide a way to update session in server side
And I think they don't provide a way to update session in server side
![Avatar](https://cdn.discordapp.com/avatars/108266952383807488/6861c0c2dea6601d7354108578ec86d0.webp?size=256)
MikeTheTechLead
Ofc this is based on some assumption, since there's nothing "Auth" built-in in next so when you refer "Auth update" I'm not sure what you refer to
Ah
There is a getServerSession function which allows you to get session serverside in the non beta version. I'm guessing it's still there in the beta version
I am not sure if you can update through that
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Eyebrowed ThrushOP
I think its read only
It doesn't allow to update
It doesn't allow to update
Things start getting confusing after they have switched to auth js from next auth.
New docs are a bit unclear