0

In my Angular app, I am logging in to the app's backend through an REST API call using $http.

When I log in to the app, the backend returns a Cookie that preserves the logged in status of the user. I want to store this cookie info somewhere so I can check via the Angular app, if the user is logged in (it could affect what page he's directed to etc).

For illustration, here's my login service code:

    loginRsrc.factory('loginSrvc', ['$http',
        'URLs', //defined in 'Constants'
        function($http, URLs){

            var signInURL = URLs.HOST + "/api/signIn";

            return function(userEmail, userPassword){
                console.log("Logging In...");
                return {
                    execute: function(){
                        return $http({
                            method: 'POST',
                            url: signInURL,
                            data: $.param({email: userEmail, password: userPassword}),
                            headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                        });
                    }
                };
            }
     }]);

How can access the Cookie and "intercept" it on receipt so I could store its status in a variable to be checked and/or updated later (i.e. at logout)?

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363

1 Answers1

0

Checkout https://docs.angularjs.org/api/ngCookies/service/$cookieStore

You will have all info related to cookie. How to retrive, store and delete it?

dhavalcengg
  • 4,678
  • 1
  • 17
  • 25