0

I am doing a project in react right now. I want to figure out a way where i could logout the user out by removing all of the session cookies in my react app.

But i do not know a solution for it. Is it possible to remove all of the cookies at the same time?

  • Depends on the kind of cookie. *HttpOnly* and/or *Path* may prevent you meddling from Javascript. – Lain Dec 01 '20 at 13:29
  • 1
    Does this answer your question? [Clearing all cookies with JavaScript](https://stackoverflow.com/questions/179355/clearing-all-cookies-with-javascript) – Lain Dec 01 '20 at 13:30

1 Answers1

-3

This is not related to React in any way, just JavaScript.

You can delete all cookies by executing:

document.cookie = '';

BUT this only works for cookies available on the client side (so not ones that are HttpOnly). It's very uncommon that session cookies from an authentication server are accessible client side, for security reasons.

In this case: you can't directly, but you need to implement a request to a logout endpoint (if any).

keul
  • 7,673
  • 20
  • 45