Skip to content

Commit

Permalink
fix(client:auth): fix hasOwnProperty instances, fix User usage (#2232)
Browse files Browse the repository at this point in the history
fixes #2212 [skip ci]
  • Loading branch information
Awk34 authored Sep 15, 2016
1 parent 94ada70 commit f41e420
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions templates/app/client/components/auth(auth)/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
*/
logout() {
$cookies.remove('token');
currentUser = new User();
currentUser = new _User();
},

/**
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
});
Expand All @@ -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');
},

/**
Expand All @@ -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;
Expand All @@ -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);
},

/**
Expand Down

0 comments on commit f41e420

Please sign in to comment.