auth.guard.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { Injectable } from '@angular/core';
  2. import { MatSnackBar } from '@angular/material/snack-bar';
  3. import {
  4. ActivatedRouteSnapshot,
  5. CanActivate,
  6. RouterStateSnapshot,
  7. Router,
  8. UrlTree,
  9. } from '@angular/router';
  10. import { BehaviorSubject, firstValueFrom, lastValueFrom, Observable, Subscription } from 'rxjs';
  11. import { USERInterface } from '../interfaces/user-interface';
  12. import { ENCService } from '../services/enc/enc.service';
  13. import { IAMService } from '../services/iam/iam.service';
  14. import { LocalstorageService } from '../services/localstorage.service';
  15. import { MCOMAUService } from '../services/mco/mcomau/mcomau.service';
  16. import { WebSocketService } from '../services/socket/web-socket.service';
  17. import { ValidationsService } from '../services/validations.service';
  18. @Injectable({
  19. providedIn: 'root',
  20. })
  21. export class AuthGuard implements CanActivate {
  22. jwt: Observable<string[]> = {} as Observable<string[]>;
  23. private _docSub: Subscription = {} as Subscription;
  24. rfc_local: string = "";
  25. user_local: string = "";
  26. private empresas_arr: any[] = [];
  27. constructor(
  28. private router: Router,
  29. public setUserStorage: LocalstorageService
  30. ) { }
  31. canActivate(
  32. route: ActivatedRouteSnapshot,
  33. state: RouterStateSnapshot
  34. ) {
  35. let bloq = false;
  36. //Se checa si existe una sesión y si no hubo cambios
  37. let isLoggedIn = localStorage.getItem('jwt') != null;
  38. if (isLoggedIn && !bloq) {
  39. return true;
  40. }
  41. return this.router.navigate(['/iam']);
  42. }
  43. }