1 line
4.6 KiB
JSON
1 line
4.6 KiB
JSON
{"ast":null,"code":"import { Observable } from 'rxjs';\nimport { LoginComponent } from '../login/login.component';\nimport * as i0 from \"@angular/core\";\nimport * as i1 from \"@angular/material/dialog\";\nimport * as i2 from \"../services/authentication.service\";\nimport * as i3 from \"@angular/router\";\nexport class AuthGuard {\n constructor(dialog, authService, router) {\n this.dialog = dialog;\n this.authService = authService;\n this.router = router;\n }\n canActivate(next, state) {\n return new Observable(observer => {\n this.authService.isAuthenticated().subscribe({\n next: res => {\n if (!res) this.openLogin();\n observer.next(res);\n },\n error: error => {\n observer.next(false);\n },\n complete: () => observer.complete()\n });\n });\n }\n openLogin() {\n const dialogRef = this.dialog.open(LoginComponent, {\n width: \"35vw\",\n data: {\n afterLogin: () => {\n dialogRef.close();\n }\n }\n });\n return dialogRef;\n }\n static #_ = this.ɵfac = function AuthGuard_Factory(t) {\n return new (t || AuthGuard)(i0.ɵɵinject(i1.MatDialog), i0.ɵɵinject(i2.AuthenticationService), i0.ɵɵinject(i3.Router));\n };\n static #_2 = this.ɵprov = /*@__PURE__*/i0.ɵɵdefineInjectable({\n token: AuthGuard,\n factory: AuthGuard.ɵfac,\n providedIn: 'root'\n });\n}","map":{"version":3,"names":["Observable","LoginComponent","AuthGuard","constructor","dialog","authService","router","canActivate","next","state","observer","isAuthenticated","subscribe","res","openLogin","error","complete","dialogRef","open","width","data","afterLogin","close","_","i0","ɵɵinject","i1","MatDialog","i2","AuthenticationService","i3","Router","_2","factory","ɵfac","providedIn"],"sources":["E:\\TekH\\Visual Studio\\WebUserManager\\DigitalData.UserManager.NgWebUI\\ClientApp\\src\\app\\auth\\auth.guard.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\r\nimport { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';\r\nimport { Observable, of } from 'rxjs';\r\nimport { AuthenticationService } from '../services/authentication.service'; // Adjust the path as necessary\r\nimport { MatDialog, MatDialogRef } from '@angular/material/dialog';\r\nimport { LoginComponent } from '../login/login.component';\r\nimport Swal from 'sweetalert2';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class AuthGuard implements CanActivate {\r\n constructor(\r\n public dialog: MatDialog,\r\n public authService: AuthenticationService,\r\n private router: Router\r\n ) {}\r\n\r\n canActivate(\r\n next: ActivatedRouteSnapshot,\r\n state: RouterStateSnapshot\r\n ): Observable<boolean> | Promise<boolean> | boolean {\r\n return new Observable(observer => {\r\n this.authService.isAuthenticated().subscribe({\r\n next: (res) => {\r\n if(!res)\r\n this.openLogin();\r\n \r\n observer.next(res)\r\n },\r\n error: (error) => {\r\n observer.next(false)\r\n },\r\n complete: () => observer.complete()\r\n });\r\n });\r\n }\r\n\r\n openLogin(): MatDialogRef<LoginComponent, any> {\r\n const dialogRef = this.dialog.open(LoginComponent, {\r\n width: \"35vw\",\r\n data: {\r\n afterLogin: () => {\r\n dialogRef.close();\r\n }\r\n }\r\n });\r\n return dialogRef;\r\n }\r\n}\r\n"],"mappings":"AAEA,SAASA,UAAU,QAAY,MAAM;AAGrC,SAASC,cAAc,QAAQ,0BAA0B;;;;;AAMzD,OAAM,MAAOC,SAAS;EACpBC,YACSC,MAAiB,EACjBC,WAAkC,EACjCC,MAAc;IAFf,KAAAF,MAAM,GAANA,MAAM;IACN,KAAAC,WAAW,GAAXA,WAAW;IACV,KAAAC,MAAM,GAANA,MAAM;EACb;EAEHC,WAAWA,CACTC,IAA4B,EAC5BC,KAA0B;IAE1B,OAAO,IAAIT,UAAU,CAACU,QAAQ,IAAG;MAC/B,IAAI,CAACL,WAAW,CAACM,eAAe,EAAE,CAACC,SAAS,CAAC;QAC3CJ,IAAI,EAAGK,GAAG,IAAI;UACZ,IAAG,CAACA,GAAG,EACL,IAAI,CAACC,SAAS,EAAE;UAElBJ,QAAQ,CAACF,IAAI,CAACK,GAAG,CAAC;QACpB,CAAC;QACDE,KAAK,EAAGA,KAAK,IAAI;UACfL,QAAQ,CAACF,IAAI,CAAC,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