0

I have a project right now, but i cannot figure out how i can remove session and req.user from the client side.

I know that in node js/express js you do req.logout() and req.session = null, but that only removes it in the backend side. I am currently using react and it does not work when i call the api for removing the session.

Any idea?

the session cookies is session.sig and session

1 Answers1

0

when client(typically browser)visit a web server(like nodejs based server you used), a session was built between client and server. As far as i know, session stores on the server side, normally it will send back the session's id(named sessionId or jsessionid ...), then web connection was built.

So if you would like to remove a session on the client side, you just need to remove the sessionId attribute's value in the cookie with this

document.cookie = "sessionIdKey=;"

you should replace 'sessionIdKey' with the key in your chrome dev tools => application => cookies => sitecookie place

this will end session connection, when this session time out, server will delete the session finally.

update: if you'd like to delete all cookies(sessionid between them), reference this: Clearing all cookies with JavaScript

Eason Yu
  • 319
  • 1
  • 5
  • Yeah, but session id's will be different from all others. My function here is "logout" function button. I want that function to go and delete all of the cookies – Magomed.Khamidov Dec 01 '20 at 11:54
  • delete all cookies will also work as it will delete sessionId, to do that you could reference : https://stackoverflow.com/questions/179355/clearing-all-cookies-with-javascript – Eason Yu Dec 01 '20 at 12:06