0

In my app I have local sign-in and Google+ sign-in. Suppose if I login with the Google+ and after I click on the signout it works perfectly. But afterwards, if I need to login with a new User it is directly logging in with previous login without asking for login. For this reason I want to delete my cookies.

The corresponding code is given below...

this is my HTML file:

<a ng-click="signout()">Signout</a>

Controller.js:

$scope.signout = function () {
       $http.get('/auth/signout').success(function(response){           
        console.log("nothing" + JSON.stringify(response));               
           var wind = window.user;               
           $cookies.wind = '';               
           console.log("windows" + JSON.stringify(wind));              
           $cookieStore.remove('wind');            
          //delete $cookies["wind"];           
        $location.path('/');

       });
    };

Where window.user is where the cookie data will be storing.

server.js:

exports.signout = function (req, res) {

    req.logout();    
    res.status(200).send("logged out");    
//     res.redirect('/');     
    console.log('server side signout function called');
};

I tried $cookieStore.remove('wind'); and delete $cookies["wind"]; But both are not working, Please tell me of other methods to solve this (and any solutions to this problem)

Eda
  • 218
  • 1
  • 3
  • 17

1 Answers1

0

This question is more networking question likely. You can't delete cookies. What you can do is only set the expired date of cookies to past.

document.cookie = mycookiename + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';

Then, browser will detect either the cookies is validate or not by checking expired date.


Important

So far, version 1.3.6, there is no way to settings cookies expired date with ngCookies prepared by AngularJS. I will recommend you to using open source instead of using ngCookies. Here's the one I am using.

https://github.com/ivpusic/angular-cookie

edisonthk
  • 1,403
  • 16
  • 35