Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  41] [ 4]  / answers: 1 / hits: 17606  / 11 Years ago, mon, july 15, 2013, 12:00:00

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.


More From » jquery

 Answers
4

Give it negative time and just set the value to nothing.



Hmm, try:



$('button .logout').click(function () {
$.cookie('userid', , -1);
});

[#77003] Friday, July 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brodyfrancisi

Total Points: 1
Total Questions: 102
Total Answers: 89

Location: Marshall Islands
Member since Mon, May 31, 2021
3 Years ago
brodyfrancisi questions
;