I am trying to build a service called AuthService
with AngularJS to use in all my controllers. Below is my code.
.factory('AuthService', function(){
return {
isAuthenticated : function(){
var AuthStatus;
Stamplay.User.currentUser().then(function(res){
if(res.user){
console.log("A");
AuthStatus = true;
}
else{
console.log("B");
AuthStatus = false;
}
}, function(err){
console.log("C");
AuthStatus = false;
});
return AuthStatus;
}
}
})
When I try to use AuthService.isAuthenticated()
in my controllers, I always get undefined
and also B
is logged to the console which means that the else
block runs fine. But I do not get any return value from the service as a whole. Any help is highly appreciated.
Thanks in advance.