33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { Component, Input } from '@angular/core';
|
|
import { jwtDecode } from 'jwt-decode';
|
|
import { EditUserModalComponent } from '../../pages/admin/users/users/edit-user-modal/edit-user-modal.component';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
import { ChangePasswordModalComponent } from '../../pages/admin/users/users/change-password-modal/change-password-modal.component';
|
|
|
|
@Component({
|
|
selector: 'app-sidebar',
|
|
templateUrl: './sidebar.component.html',
|
|
styleUrl: './sidebar.component.css'
|
|
})
|
|
export class SidebarComponent {
|
|
@Input() isVisible: boolean = false;
|
|
isSuperAdmin: boolean = false;
|
|
username: string = "";
|
|
decodedToken: any = "";
|
|
constructor(public dialog: MatDialog) {}
|
|
|
|
ngOnInit(): void {
|
|
const token = localStorage.getItem('loginToken');
|
|
if (token) {
|
|
try {
|
|
this.decodedToken = jwtDecode(token);
|
|
this.isSuperAdmin = this.decodedToken.roles.includes('ROLE_SUPER_ADMIN');
|
|
localStorage.setItem('isSuperAdmin', String(this.isSuperAdmin));
|
|
this.username = this.decodedToken.username;
|
|
} catch (error) {
|
|
console.error('Error decoding JWT:', error);
|
|
}
|
|
}
|
|
}
|
|
}
|