ekart/src/app/core/guards/role-guard.ts
2026-03-16 13:05:06 +05:30

13 lines
407 B
TypeScript

import { CanActivateFn } from "@angular/router";
import { inject } from "@angular/core";
import { AuthService } from "@core/services/auth-service";
export const roleGuard: CanActivateFn = (route, state) => {
const authService = inject(AuthService);
// get role from route data passed in route config.
const roles = route.data["roles"] as string[];
return roles && authService.hasRoles(roles);
};