Search code examples
angularjsnode.jscookiesvps

Cookies work great on localhost but does not work on VPS


I am using nodejs and angularjs 1.6.4. Everything works great on localhost but when I push my code to Digital Ocean droplet through Github, the cookies does not work. Everything that I saved to cookie does not appear in Cookie Storage. Why does it happen ?

UPDATE A warning appears when I go to Login page on VPS: "This page includes a password or credit card input in a non-secure context. A warning has been added to the URL bar"

Here is the relevant code:

$scope.login = function () {

      UserService.login($scope.user).then(function (result) {
        if (result.data.success) {
          $rootScope.userLogin = result.data.data.name;

          //------------------
          var day = new Date();
          day.setDate(day.getDay() + 30);

          var options = {
            domain: "localhost",
            httpOnly: true,
            expires: day
          };
          // cookie does not work, nothing in Cookie Storage
          // but it works perfectly on localhost
          $cookies.put('token', result.data.data.token, options);
          $cookies.put('name', result.data.data.name, options);
          // the session storage work greatly
          $sessionStorage.user = 'heheeheh';
          flash.success = result.data.message;
          $state.go('home');
        } else {
          flash.error = result.data.message;
        }
      });
    } 

UPDATE:

I created another VPS on amazon ec2 but it still does not work.


Solution

  • I found that just change the domain options from localhost to server's IP