title: How to avoid $cookies getting deleted when refresh page or change window location?
body: <p>I am trying to maintain session in frontend. However, I found out that whenever I refresh the browser or change <code>window.location</code> . The cookie disappears.</p>
  
  <pre><code>      angular
          .module('myservices')
          .factory('myAuthentication', Authentication);
  
        Authentication.$inject = ['$cookies', '$http', '$q', '$rootScope'];
  
        function Authentication($cookies, $http, $q, $rootScope){
  
          var Authentication = {
            login                    : login,
            getAuthenticatedAccount  : getAuthenticatedAccount,
            isAuthentiate            : isAuthentiate,
            setAuthenticateAccount   : setAuthenticateAccount,
            unAuthenticate           : unAuthenticate,
          };
  
          return Authentication;
  
          function login(email, password){
            $http.post('login/', {
              email: email, password: password
            }).then(loginSuccess, loginError);
            function loginSuccess(response){
  
              Authentication.setAuthenticateAccount(response.data);
  
              $rootScope.$broadcast('login', "login");
  
              // changing window location will delete the cookies
              window.location = '/';
            }
            function loginError(response){
              console.log('error');
            }
          }
  
          function getAuthenticatedAccount(){
            if (!$cookies.authenticatedAccount){
              return ;
            }
            return JSON.parse($cookies.authenticatedAccount);
          }
  
          function isAuthentiate(){
            return !!$cookies.authenticatedAccount;
          }
  
          function setAuthenticateAccount(account){
            $cookies.authenticatedAccount = JSON.stringify(account);
          }
  
        }
  </code></pre>
  
  <p>I tested this in both firefox and safari and I make sure that I tested both unchecked and checked disable cache in firefox.</p>
  
  <p>Is there any other setting in angular that keep the cookie persistant?</p>