How can I remove session or logout users from server components?
Answered
Great golden digger wasp posted this in #help-forum
Great golden digger waspOP
I want to invalidate or set a session to null from server components but unable to find any solutions anywhere. Can someone direct me to a guide?
Answered by Toyger
next-auth set cookie
probably if it not secure should be something like
__Secure-authjs.session-tokenprobably if it not secure should be something like
authjs.session-token you need to check which exactly name it set for your site and remove it, and theoretically it should kill user session.4 Replies
Toyger
hmm, never thought about that, but probably you can redirect user to some page where you'll have next-auth signOut() function called in useEffect()
otherwise if you really want server only, you need to kill next-auth cookies, theoretically it should kill session
useEffect(()=>{
signOut()
},[])otherwise if you really want server only, you need to kill next-auth cookies, theoretically it should kill session
@Toyger hmm, never thought about that, but probably you can redirect user to some page where you'll have next-auth signOut() function called in useEffect()
js
useEffect(()=>{
signOut()
},[])
otherwise if you really want server only, you need to kill next-auth cookies, theoretically it should kill session
Great golden digger waspOP
Thanks for the response. I would like to kill the session, how can I have a workaround to this? I've set up a if statement that checks my JWT (which I get from my custom backend) expiry time and once it expires I want kill the session or set it to null.
@Great golden digger wasp Thanks for the response. I would like to kill the session, how can I have a workaround to this? I've set up a if statement that checks my **JWT** (which I get from my custom backend) expiry time and once it expires I want kill the session or set it to null.
Toyger
next-auth set cookie
probably if it not secure should be something like
__Secure-authjs.session-tokenprobably if it not secure should be something like
authjs.session-token you need to check which exactly name it set for your site and remove it, and theoretically it should kill user session.Answer
@Toyger next-auth set cookie `__Secure-authjs.session-token`
probably if it not secure should be something like `authjs.session-token` you need to check which exactly name it set for your site and remove it, and theoretically it should kill user session.
Great golden digger waspOP
Gotcha! Thank you for the quick response. Appreciated it!