-
Notifications
You must be signed in to change notification settings - Fork 0
JS IsLoggedInAsync
Let's say you have a public page, but if the user is logged in you want to show special information to them. You'll need to detect if a user is logged in before you make an $http call, right? It's not guaranteed that this will work, because isLoggedIn() is actually an async call. If you want to force something to wait until after isLoggedIn() is successful before it gets called, you should include Auth.isLoggedInAsync:
$scope.isLoggedInAsync = Auth.isLoggedInAsync;
isLoggedInAsync takes a callback function as an input, and passes the callback function a true boolean if the user is logged in, and a false if the user is not. You can call it like so:
$scope.isLoggedInAsync(callback(bool) {
if (bool) { /** do thing if they’re logged in **/ }
else { /** do different thing if they’re not logged in **/ }
});
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links