Replace your call with service:
Solution A: .then(successCallback, errorCallback) :
Auth.getUser().then( function (response) { ... }, // success handler function (response) { // error handler // case where user is not logged in // or http request fails });
or
Solution B: .then(successCallback).catch(errorCallback) :
Auth.getUser() .then(function (response) { ... }) // success handler .catch(function (response) { // error handler // case where user is not logged in // or http request fails });
Explanation:
Your getUser method getUser defined as follows:
authFactory.getUser = function () { if (AuthToken.getToken()) return $http.get('/api/me', { cache: true }); else { return $q.reject({ message: 'User has no token.' }); } }
But the abbreviated success and error methods are for $http . They do not exist in the angular prom $q API. Therefore, when the user is not registered, because you return the promise of $q , you get undefined is not a function .
Methods that you can call for the $q prom object ( link to documentation ):
then(successCallback, errorCallback, notifyCallback)catch(errorCallback) , which is short for promise.then(null, errorCallback)finally(callback, notifyCallback)
source share