mardi 26 janvier 2016

Angular Satellizer not sending token with reqiest

looking into Ionic and Laravel as an API.

Every on the API is set up, but for some reason the Satellizer package isn't sending the token with the request.

After a user is logged in, I see the satellizer token in local storage, but my API then fails when calling the next request saying that not token was provided.

However, if I hardcode the url including the token then it works.

Im using this guide: http://ift.tt/1OXqMQD

And this is the main section im working on:

.controller('AuthCtrl', function($scope, $location, $stateParams, $ionicHistory, $http, $state, $auth, $rootScope) {
$scope.loginData = {}
$scope.loginError = false;
$scope.loginErrorText;

$scope.login = function() {

    var credentials = {
        email: $scope.loginData.email,
        password: $scope.loginData.password
    }

    console.log(credentials);

    $auth.login(credentials).then(function() {
        // Return an $http request for the authenticated user
        $http.get('http://ift.tt/1S9HUJg').success(function(response){
            // Stringify the retured data
            var user = JSON.stringify(response.user);

            // Set the stringified user data into local storage
            localStorage.setItem('user', user);

            // Getting current user data from local storage
            $rootScope.currentUser = response.user;
            // $rootScope.currentUser = localStorage.setItem('user');;

            $ionicHistory.nextViewOptions({
              disableBack: true
            });

            $state.go('app.jokes');
        })
        .error(function(){
            $scope.loginError = true;
            $scope.loginErrorText = error.data.error;
            console.log($scope.loginErrorText);
        })
    });
}

})

That url should be sending the token right? Any ideas where I might be going wrong?

EDIT: Just checked the network tab and it shows this:

enter image description here

So its somehow being removed or not seen at the API? whereas ?token=FOO is?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire