Currently in my AngularJS project, I am utilizing $q for promises and feeling a bit overwhelmed with the usage. How can I resolve this promise-related issue?
My goal is to either return the user when isLoggedInPromise() is triggered or provide a response of "AUTH_REQUIRED".
Appreciate any help and guidance!
function isLoggedInPromise() {
$q.when(userWithAllData()).then(function(user) {
return user;
});
$q.when(userWithAllData()).reject(function() {
return "AUTH_REQUIRED";
});
}
function userWithAllData(){
var deferral = $q.defer();
var query = new Parse.Query(Parse.User);
query.include(["info", "info.rank", "privateInfo"]);
query.get(Parse.User.current().id).then(function (loadedUser){
deferral.resolve( loadedUser );
});
return deferral.promise;
}