Skip to content

Commit f41e420

Browse files
authored
fix(client:auth): fix hasOwnProperty instances, fix User usage (#2232)
fixes #2212 [skip ci]
1 parent 94ada70 commit f41e420

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Diff for: templates/app/client/components/auth(auth)/auth.service.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
5757
*/
5858
logout() {
5959
$cookies.remove('token');
60-
currentUser = new User();
60+
currentUser = new _User();
6161
},
6262

6363
/**
@@ -103,7 +103,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
103103
* @return {Promise}
104104
*/
105105
getCurrentUser(callback?: Function) {
106-
var value = currentUser.hasOwnProperty('$promise')
106+
var value = _.get(currentUser, '$promise')
107107
? currentUser.$promise
108108
: currentUser;
109109

@@ -135,7 +135,8 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
135135
isLoggedIn(callback?: Function) {
136136
return Auth.getCurrentUser(undefined)
137137
.then(user => {
138-
var is = user.hasOwnProperty('role');
138+
let is = _.get(user, 'role');
139+
139140
safeCb(callback)(is);
140141
return is;
141142
});
@@ -147,7 +148,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
147148
* @return {Bool}
148149
*/
149150
isLoggedInSync() {
150-
return currentUser.hasOwnProperty('role');
151+
return !!_.get(currentUser, 'role');
151152
},
152153

153154
/**
@@ -160,9 +161,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
160161
hasRole(role, callback?: Function) {
161162
return Auth.getCurrentUser(undefined)
162163
.then(user => {
163-
var has = user.hasOwnProperty('role')
164-
? hasRole(user.role, role)
165-
: false;
164+
let has = hasRole(_.get(user, 'role'), role);
166165

167166
safeCb(callback)(has);
168167
return has;
@@ -176,7 +175,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
176175
* @return {Bool}
177176
*/
178177
hasRoleSync(role) {
179-
return hasRole(currentUser.role, role);
178+
return hasRole(_.get(currentUser, 'role'), role);
180179
},
181180

182181
/**

0 commit comments

Comments
 (0)