Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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