How to use include "users" in restangular login?

41 Views Asked by At

I want to store token and user information in local storage ,things like store token and userId are okay except I can't include users detail information like email

this.login = function (data) {
  var loginResults = Restangular.one('/users/login')
    .post(undefined, data)
    .then(function (data) {
      var mytoken = data.id;
      storeToken(data);
      Restangular.setDefaultHeaders({ accept: 'application/json', access_token: mytoken });
    },
      function (Response) {
        console.log("There was an error.");

      });

  return loginResults;
}
1

There are 1 best solutions below

0
On

Finally I got the correct answer to include "user" here is the result....

  this.login = function (data) {

    var loginResults = Restangular.one('/persons/login')
      .post(undefined, data, {
        include: "user"
      })
      .then(function (data) {
        var mytoken = data.id;
        storeToken(data);

        Restangular.setDefaultHeaders({ accept: 'application/json', access_token: mytoken });


        $state.go('home');


      }, function (Response) {
        console.log("There was an error.");
        alert("Login Failed");

      });

    return loginResults;
  }