Pretty simple. I set this cookie in my route /user/login:
if (rememberMe) {
console.log('Login will remembered.');
res.cookie('user', userObj, { signed: true, httpOnly: true, path: '/' });
}
else {
console.log('Login will NOT be remembered.');
}
I already set my secret for cookie-parser:
app.use(cookieParser('shhh!'));
Pretty simple stuff. Everything works fine, as I can get everything I stored in the cookie:
app.use(function (req, res, next) {
if (req.signedCookies.user) {
console.log('Cookie exists!');
req.session.user = req.signedCookies.user;
}
else {
console.log('No cookie found.');
}
next();
});
This middleware is called first, so for the argument "Cookie exists!" always writes to my console if the cookie is valid.
The problem is that I am trying to delete a cookie. I tried res.clearCookie('user'), res.cookie('user', '', { expires: new Date() })and I tried passing in the same flags (that I go to res.cookie()in /user/login). I tried using combinations of these methods, but nothing worked.
, cookie ( "Cookie exists!!" ), - . :
route.get('/user/logout', function (req, res, next) {
res.clearCookie('user');
req.session.destroy();
util.response.ok(res, 'Successfully logged out.');
});
, cookie;
res.cookie('user', {}, { signed: true, httpOnly: true, path: '/' })
, cookie .