Skip to content
Advertisement

How to delete a cookie in Reactjs

I am developing a web app with react front-end and node baack-end

I want to delete the cookie being stored so that I can successfully be able to logout the user. I have tried using the js-cookie library and react-cookie library but it does not work.

nav_component:

JavaScript

How I set the cookie in the backend:

JavaScript

It should be noted that in my backend there is some code related to JWT tokens but I have not yet implemented that in my front-end. The only thing that I have implemented is the cookie and session.

Advertisement

Answer

In my backend I added this code for logging out to which I made an axios reques from the frontend:

JavaScript

Whereby “userId” id the name of the cookie

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement