Fixed the issue where the sidebar nav doesn't load

pull/3895/head
Jamie Rees 6 years ago
parent 9f5c19ecf6
commit e141743f08

@ -167,8 +167,8 @@
<div [ngClass]="user.name && roleClass()"> <div>
<app-my-nav [showNav]="showNav" [isAdmin]="isAdmin" [applicationName]="applicationName" [username]="user.name" (logoutClick)="logOut();" <app-my-nav [showNav]="showNav" [isAdmin]="isAdmin" [applicationName]="applicationName" [username]="username" (logoutClick)="logOut();"
(themeChange)="onSetTheme($event)"></app-my-nav> (themeChange)="onSetTheme($event)"></app-my-nav>

@ -28,6 +28,7 @@ export class AppComponent implements OnInit {
public voteEnabled = false; public voteEnabled = false;
public applicationName: string = "Ombi" public applicationName: string = "Ombi"
public isAdmin: boolean; public isAdmin: boolean;
public username: string;
private checkedForUpdate: boolean; private checkedForUpdate: boolean;
@ -86,6 +87,9 @@ export class AppComponent implements OnInit {
this.currentUrl = event.url; this.currentUrl = event.url;
if (event instanceof NavigationStart) { if (event instanceof NavigationStart) {
this.user = this.authService.claims(); this.user = this.authService.claims();
if(this.user && this.user.username) {
this.username = this.user.username;
}
this.isAdmin = this.authService.hasRole("admin"); this.isAdmin = this.authService.hasRole("admin");
this.showNav = this.authService.loggedIn(); this.showNav = this.authService.loggedIn();
@ -101,17 +105,6 @@ export class AppComponent implements OnInit {
}); });
} }
public roleClass() {
if (this.user) {
if (this.user.roles.some(r => r === "Admin")) {
return "adminUser";
} else if (this.user.roles.some(r => r === "PowerUser")) {
return "powerUser";
}
}
return "user";
}
public openMobileApp(event: any) { public openMobileApp(event: any) {
event.preventDefault(); event.preventDefault();
if (!this.customizationSettings.applicationUrl) { if (!this.customizationSettings.applicationUrl) {

@ -11,4 +11,5 @@ export interface IUserLogin {
export interface ILocalUser { export interface ILocalUser {
roles: string[]; roles: string[];
name: string; name: string;
username:string;
} }

@ -59,8 +59,11 @@ export class AuthService extends ServiceHelpers {
} }
public hasRole(role: string): boolean { public hasRole(role: string): boolean {
if (this.claims().roles) {
return this.claims().roles.some(r => r.toUpperCase() === role.toUpperCase()); return this.claims().roles.some(r => r.toUpperCase() === role.toUpperCase());
} }
return false;
}
public logout() { public logout() {
localStorage.removeItem("id_token"); localStorage.removeItem("id_token");

Loading…
Cancel
Save