Skip to content

Commit

Permalink
simplified roles
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenSoftware committed Feb 2, 2021
1 parent f4726b4 commit 40aa58b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions libs/auth/src/lib/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class AuthService {
localStorage.setItem(LocalStorageKey.rememberMe, authSession.rememberMe.toString());
localStorage.setItem(LocalStorageKey.roles, btoa(authSession.roles.toString()));

if (!this.rolesEqual(userRolesVar(), authSession.roles)) {
if (!this.rolesEqual(this.roles, authSession.roles)) {
if (authSession.roles) userRolesVar(authSession.roles);
else userRolesVar([]);
}
Expand All @@ -113,16 +113,16 @@ export class AuthService {

userHasRole(role: string | string[]) {
if (role) {
if (typeof role === 'string') return userRolesVar().some(r => r === role);
else return userRolesVar().some(r => role.includes(r));
if (typeof role === 'string') return this.roles.some(r => r === role);
else return this.roles.some(r => role.includes(r));
}
return false;
}

userNotInRole(role: string | string[]) {
if (role) {
if (typeof role === 'string') return !userRolesVar().some(r => r === role);
else return intersection(userRolesVar(), role).length === 0;
if (typeof role === 'string') return !this.roles.some(r => r === role);
else return intersection(this.roles, role).length === 0;
}
return true;
}
Expand Down

0 comments on commit 40aa58b

Please sign in to comment.