added role.guard.ts.ts again
Some checks failed
Build Docker Image / Restart Docker Compose (push) Has been cancelled
Build Docker Image / Build Docker Image (push) Has been cancelled

Signed-off-by: supphakitd <67319010028@technictrang.ac.th>
This commit is contained in:
2025-12-03 06:56:28 +07:00
parent d5026535d0
commit a06337d9b5

View File

@@ -0,0 +1,27 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
@Injectable({
providedIn: 'root',
})
export class RoleGuard {
constructor(private router: Router) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
const denyRole = route.data?.['denyRole'];
const usrrol = localStorage.getItem('usrrol');
if (denyRole && usrrol === denyRole) {
// blocked: navigate away (adjust target as needed)
this.router.navigate(['/']);
return false;
}
return true;
}
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
return this.canActivate(route, state);
}
}