temporary cache wipe on logout

This commit is contained in:
Timo 2020-11-26 22:23:56 +02:00
parent 9723f3be4a
commit ede4c09252

View File

@ -3,6 +3,7 @@ import { KeycloakService } from 'keycloak-angular';
import { KeycloakProfile } from 'keycloak-js';
import jwt_decode from 'jwt-decode';
import { User, UserControllerService } from '@redaction/red-ui-http';
import { wipeCaches } from '@redaction/red-cache';
export class UserWrapper {
constructor(private _currentUser: KeycloakProfile, public roles: string[], public id: string) {}
@ -35,12 +36,10 @@ export class UserService {
private _currentUser: UserWrapper;
private _allUsers: User[];
constructor(
private readonly _keycloakService: KeycloakService,
private readonly _userControllerService: UserControllerService
) {}
constructor(private readonly _keycloakService: KeycloakService, private readonly _userControllerService: UserControllerService) {}
logout() {
wipeCaches();
this._keycloakService.logout(window.location.origin);
}
@ -57,9 +56,7 @@ export class UserService {
}
get eligibleUsers() {
return this._allUsers.filter(
(u) => u.roles.indexOf('RED_USER') >= 0 || u.roles.indexOf('RED_MANAGER') >= 0
);
return this._allUsers.filter((u) => u.roles.indexOf('RED_USER') >= 0 || u.roles.indexOf('RED_MANAGER') >= 0);
}
async loadAllUsersIfNecessary() {
@ -78,11 +75,7 @@ export class UserService {
const token = await this._keycloakService.getToken();
const decoded = jwt_decode(token);
const userId = decoded.sub;
this._currentUser = new UserWrapper(
await this._keycloakService.loadUserProfile(false),
this._keycloakService.getUserRoles(true),
userId
);
this._currentUser = new UserWrapper(await this._keycloakService.loadUserProfile(false), this._keycloakService.getUserRoles(true), userId);
}
get user() {
@ -98,11 +91,7 @@ export class UserService {
}
getName(user?: User) {
return user
? user.firstName && user.lastName
? `${user.firstName} ${user.lastName}`
: user.username
: undefined;
return user ? (user.firstName && user.lastName ? `${user.firstName} ${user.lastName}` : user.username) : undefined;
}
isManager(user?: User): boolean {
@ -120,10 +109,6 @@ export class UserService {
}
private _hasAnyRedRole(u: User) {
return (
u.roles.indexOf('RED_USER') >= 0 ||
u.roles.indexOf('RED_MANAGER') >= 0 ||
u.roles.indexOf('RED_ADMIN') >= 0
);
return u.roles.indexOf('RED_USER') >= 0 || u.roles.indexOf('RED_MANAGER') >= 0 || u.roles.indexOf('RED_ADMIN') >= 0;
}
}