clearCookie only works in get route but not post route?

Viewed 11
meRouter.get('/logout', (req, res) => {
     return res.clearCookie('jwt-token') 
}) 

I have a route in express that should handle a clear cookie, which determines if the user is logged into my app. I am using localhost:3001 for backend and 3000 for frontend

function logout() {     
useEffect(() => {         
    axios.get('http://localhost:3001/api/me/logout', {withCredentials: true})}, 
[]) } 

This is my axios request. It should be including my cookies on request but for some reason clearCookie simply does not work when using a 'POST' route instead of a GET route.

SIDE NOTE: My GET logout route was working and clearing the cookie but was displaying some console errors, and it was fixed by adding to my server file. Now I get no errors and cookies get deleted on GET request, but does not work on POST. I could just let it be on the get route but I want to know what is going on as a POST route makes more sense to use.

app.use(cors({
  origin: "http://localhost:3000",
  credentials: true,
}));
0 Answers
Related