我正在尝试在angular和loopback上实现一个简单的登录。
我使用以下控制器进行登录。
(function(angular){
'use strict';
//Module Fetch
angular
.module('frontend')
.controller('LoginController',LoginController);
LoginController.$inject = [
'$log',
'$location',
'ExeboardUser',
'LoopBackAuth'
];
function LoginController(
$log,
$location,
ExeboardUser,
LoopBackAuth
){
var vm = this;
vm.user={username:'',password:''};
vm.loggedIn = ExeboardUser.isAuthenticated();
console.log("login"+vm.loggedIn)
vm.login = function(){
console.log("Logging in...");
var user = vm.user.username;
var password = vm.user.password;
ExeboardUser.login({username:user,password:password})
.$promise
.then(function(){
console.log("Login Succesful");
var next = $location.nextAfterLogin || '/';
$location.nextAfterLogin = null;
$location.path(next);
$location.path('/dashboard');
},
function(error) {
console.log("Error login: "+error);
});
}
vm.logout = function(){
ExeboardUser.logout();
LoopBackAuth.clearUser();
LoopBackAuth.clearStorage();
}
}
})(angular)
当我登录时,我成功得到以下回复:
{"id":"IzVg5NH2l4oCOskzIFrhUoSIDcvc6Ht5sy7AHgnjutB8etx2Gb77Dz1bAdFm4HVZ","ttl":1209600,"created":"2016-05-27T15:44:26.648Z","userId":1,"user":{"name":"test","last_name":"t","phestone":55485698,"realm":null,"username":"test_login","credentials":null,"challenges":null,"email":"testlogin@hotmail.com","emailVerified":null,"status":null,"created":null,"lastUpdated":null,"id":1}}
但是在调用注销功能时。我收到了这个回复
{"error":{"name":"Error","status":500,"message":"could not find accessToken","stack":"Error: could not find accessToken
令牌确实出现在window.storage中,但是我不明白为什么即使我已经调用了登录,注销也会生成未经身份验证的请求。还有什么我必须添加到注销请求以使其发送访问令牌吗?