Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In my Angular app I created a service:

.factory('Auth', function($http) {
    return {
        is_authenticated: function() {
            return $http.get('/api/users/is_authenticated');
        }
    }
});

My method in my API backed by Laravel:

public function is_authenticated()
{
    if(Auth::check())
    {
        return Response::json(array('authenticated' => true));
    }

    return Response::json(array('authenticated' => false));
}

And then in my controller:

    Auth.is_authenticated()
        .success(function(data) {
            $scope.is_authenticated = data.authenticated;
            if(data.authenticated)
                console.log('yes');
        });

When I go to /api/users/is_authenticated I see nothing on the page, however, when I echo Auth::check() there is a 1 on the page.

In my view I have a list with ng-show="is_authenticated" but it's not working.

What am I doing wrong here? I'm failing to see the problem. Why is 'yes' not being logged to the console?

And yes, I have injected the Auth service into my controller.

share|improve this question
    
what did you get in the console.log after success ? –  Kalhano Toress Pamuditha Sep 19 at 6:25
    
Absolutely nothing. –  Billy Assim Sep 19 at 6:26
    
execute inside the success ? –  Kalhano Toress Pamuditha Sep 19 at 6:30
    
It is executed inside the success? –  Billy Assim Sep 19 at 6:31
    
Try to check for error simply Auth.is_authenticated().success(function(data){}).error(function(reason){console‌​.log(reason);}) –  Whisher Sep 19 at 7:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.