1
angular.module('starter')

   .controller('LoginCtrl', function($scope, $location, $stateParams, $ionicHistory, $http, $state, $auth, $rootScope) {

    $scope.loginForm = {}
    $scope.loginError = false;
    $scope.loginErrorText;

    $scope.login = function() {

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

        console.log(credentials);

        $auth.login(credentials).then(function() {
             console.log('im in login function' );
            // Return an $http request for the authenticated user
            $http.get('http://localhost:8000/api/v1/auth/user').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);
            })
        });
    }
});

当我调用登录功能时,我收到此错误

POST http://localhost:8100/auth/login 404(未找到)

卫星发射器有问题吗?

4

1 回答 1

1

我也遇到了同样的问题。我刚刚添加

$authProvider.loginUrl = myServer+ 'oauth/token';
$authProvider.tokenName = 'access_token';
$authProvider.tokenPrefix = 'myServerAuth';
$authProvider.tokenHeader = 'Authorization';
$authProvider.tokenType = 'Bearer';

在我的配置中,它运行良好。

于 2017-08-28T13:01:00.133 回答