Depending on the result of an asynchronous AJAX request return true or false?

How to make a function checkEitherLoggedInOrNot() to return true or false depending on the result of an asynchronous AJAX request? Easier - during the transition to .then we return true, otherwise false.
export checkEitherLoggedInOrNot function(){ 
 let options = {
method:'GET',
credentials:'include',
 mode: 'cors'
};
ajaxRequest('https://repo.asda.ru/app_dev/Auth',options)
 .then(data => {
console.log(data)
})
 .catch(error => console.log(error));
}
June 14th 19 at 20:11
2 answers
June 14th 19 at 20:13
Solution
export checkEitherLoggedInOrNot function(){ 
 let options = {
method:'GET',
credentials:'include',
 mode: 'cors'
};
 return ajaxRequest('https://repo.asda.ru/app_dev/Auth',options)
 .then(data => {
 //It returns what you need
 return data;
})
 .catch(error => console.log(error));
}

checkEitherLoggedInOrNot().then(result => { 
 // where result is the result you got
 })
June 14th 19 at 20:15
if (response) { // some condition
resolve(true);
} else {
resolve(false);
}

Find more questions by tags JavaScript