admin管理员组文章数量:1307638
I am having a hard time removing a cookie when the logout button is clicked. I currently have a logout button with the class logout. and this is the simple jquery line I am trying to put to remove the cookie but it is not working.
$('button .logout').click(function () {
$.cookie('userid', null);
};
userid is the name of the cookie.
Oh I am using a signed cookie, not sure if that changes anything?
EDIT:
Here is how I set the cookie:
exports.loginPost = function(req, res, next) {
console.log("here 1");
passport.authenticate('local', function(err, user, info) {
if (err) { return next(err) }
if (!user) {
return res.render('loginError', {title: 'Weblio'}); }
req.logIn(user, function(err) {
if (err) { return next(err); }
console.log(JSON.stringify(user));
res.cookie('userid', user._id, { maxAge: 900000, signed: true });
res.redirect('userProfile');
});
})(req, res, next);
};
And using a simple express - node js cookieParser with a secret in it.
I am having a hard time removing a cookie when the logout button is clicked. I currently have a logout button with the class logout. and this is the simple jquery line I am trying to put to remove the cookie but it is not working.
$('button .logout').click(function () {
$.cookie('userid', null);
};
userid is the name of the cookie.
Oh I am using a signed cookie, not sure if that changes anything?
EDIT:
Here is how I set the cookie:
exports.loginPost = function(req, res, next) {
console.log("here 1");
passport.authenticate('local', function(err, user, info) {
if (err) { return next(err) }
if (!user) {
return res.render('loginError', {title: 'Weblio'}); }
req.logIn(user, function(err) {
if (err) { return next(err); }
console.log(JSON.stringify(user));
res.cookie('userid', user._id, { maxAge: 900000, signed: true });
res.redirect('userProfile');
});
})(req, res, next);
};
And using a simple express - node js cookieParser with a secret in it.
Share Improve this question edited Jul 15, 2013 at 1:12 Lion789 asked Jul 15, 2013 at 0:57 Lion789Lion789 4,48212 gold badges60 silver badges101 bronze badges 2- For security reasons, authentication cookies should be marked as HTTP Only, which means they aren't accessible from javascript and need to be cleared on the server. – Jason P Commented Jul 15, 2013 at 1:07
- Ok, so do I render a logout page and remove the cookie during the render or something? – Lion789 Commented Jul 15, 2013 at 1:16
1 Answer
Reset to default 4Give it negative time and just set the value to nothing.
Hmm, try:
$('button .logout').click(function () {
$.cookie('userid', "", -1);
});
本文标签: javascriptHow to remove a cookie on logout buttonStack Overflow
版权声明:本文标题:javascript - How to remove a cookie on logout button? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741810877a2398786.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论