diff --git a/templates/app/client/components/auth(auth)/auth.service.js b/templates/app/client/components/auth(auth)/auth.service.js index ac17e15ce..e38a12632 100644 --- a/templates/app/client/components/auth(auth)/auth.service.js +++ b/templates/app/client/components/auth(auth)/auth.service.js @@ -57,7 +57,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use */ logout() { $cookies.remove('token'); - currentUser = new User(); + currentUser = new _User(); }, /** @@ -103,7 +103,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use * @return {Promise} */ getCurrentUser(callback?: Function) { - var value = currentUser.hasOwnProperty('$promise') + var value = _.get(currentUser, '$promise') ? currentUser.$promise : currentUser; @@ -135,7 +135,8 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use isLoggedIn(callback?: Function) { return Auth.getCurrentUser(undefined) .then(user => { - var is = user.hasOwnProperty('role'); + let is = _.get(user, 'role'); + safeCb(callback)(is); return is; }); @@ -147,7 +148,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use * @return {Bool} */ isLoggedInSync() { - return currentUser.hasOwnProperty('role'); + return !!_.get(currentUser, 'role'); }, /** @@ -160,9 +161,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use hasRole(role, callback?: Function) { return Auth.getCurrentUser(undefined) .then(user => { - var has = user.hasOwnProperty('role') - ? hasRole(user.role, role) - : false; + let has = hasRole(_.get(user, 'role'), role); safeCb(callback)(has); return has; @@ -176,7 +175,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use * @return {Bool} */ hasRoleSync(role) { - return hasRole(currentUser.role, role); + return hasRole(_.get(currentUser, 'role'), role); }, /**