13 lines
407 B
TypeScript
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);
|
|
};
|