Skip to content
Advertisement

how to delete cookie on logout in express + passport js?

I want to “delete cookies on logout”. I am not able to do that. I googled for answer and found following ways:

  1. Assign new date of expiration to cookie

    res.cookie('connect.sid', '', {expires: new Date(1), path: '/' });

  2. Delete cookie using below lines

    res.clearCookie('connect.sid', { path: '/' });

I tried both ways individually but they do not delete the cookie.

Here is my code:

routes.js

JavaScript

};

server.js

JavaScript

Advertisement

Answer

You can use req.session.destroy in logout route to destroy the session below is the code for reference 🙂

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