You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

14 lines
517 B

  1. import {CanActivateFn, Router} from '@angular/router';
  2. import {inject} from "@angular/core";
  3. import {AccountService} from "@app/_services";
  4. import {Role} from "@app/_helpers/role";
  5. export const userGuard: CanActivateFn = (route, state) => {
  6. const accountService = inject(AccountService);
  7. if (accountService.isLoggedIn() && accountService.userHasRole(Role.ROLE_USER)) {
  8. return true;
  9. }
  10. inject(Router).navigate(['/account/login'], { queryParams: { returnUrl: state.url }});
  11. return false;
  12. };