I've written a service Auth with a function is_authenticated() that returns $http.get('/api/users/is_authenticated')
When I visit the API endpoint in the browser, I see the proper JSON.
{"authenticated":true}
when the user is authenticated, and false when the user is not.
However, my console.log() below returns false 100% of the time (and it also logs it twice, not just once).
What's the problem here?
var is_authenticated = false;
Auth.is_authenticated()
.success(function(data) {
is_authenticated = data.authenticated;
});
console.log(is_authenticated);
Service:
.factory('Auth', function($http) {
return {
is_authenticated: function() {
return $http.get('/api/users/is_authenticated');
},