6befb0d01affa8a7d8b4682be6920cffabc6c39b500c2d451115422e832486fc.json 1.4 KB

1
  1. {"ast":null,"code":"import * as i0 from \"@angular/core\";\nimport * as i1 from \"@angular/router\";\nimport * as i2 from \"src/app/services/auth.service\";\nexport let AuthGuard = /*#__PURE__*/(() => {\n class AuthGuard {\n constructor(router, authService) {\n this.router = router;\n this.authService = authService;\n }\n canActivate(route, state) {\n const currentUser = this.authService.userValue;\n if (currentUser) {\n // check if route is restricted by role\n if (route.data.roles && route.data.roles.indexOf(currentUser.role) === -1) {\n // role not authorised so redirect to home page\n this.router.navigate(['/']);\n return false;\n }\n // authorised so return true\n return true;\n }\n // not logged in so redirect to login page with the return url\n this.router.navigate(['/login'], {\n queryParams: {\n returnUrl: state.url\n }\n });\n return false;\n }\n static #_ = this.ɵfac = function AuthGuard_Factory(t) {\n return new (t || AuthGuard)(i0.ɵɵinject(i1.Router), i0.ɵɵinject(i2.AuthService));\n };\n static #_2 = this.ɵprov = /*@__PURE__*/i0.ɵɵdefineInjectable({\n token: AuthGuard,\n factory: AuthGuard.ɵfac,\n providedIn: 'root'\n });\n }\n return AuthGuard;\n})();","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}