ngx-sp-auth 4.23.9 → 4.23.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import { HTTP_INTERCEPTORS, HttpHeaders, HttpClient, HttpParams, HttpResponse }
5
5
  import * as i1$2 from '@azure/msal-angular';
6
6
  import { MsalInterceptor, MsalGuard, MsalModule, MSAL_GUARD_CONFIG } from '@azure/msal-angular';
7
7
  import { LogLevel, PublicClientApplication, InteractionType } from '@azure/msal-browser';
8
- import { take as take$1, tap as tap$1, map as map$1, switchMap as switchMap$1 } from 'rxjs/operators';
8
+ import { take as take$1, tap as tap$1, map as map$1, filter as filter$1, switchMap as switchMap$1 } from 'rxjs/operators';
9
9
  import * as i1$1 from '@angular/router';
10
10
  import { RouterLink, NavigationEnd, RouterOutlet, Router, PRIMARY_OUTLET } from '@angular/router';
11
11
  import * as i3 from 'ngx-sp-infra';
@@ -807,8 +807,8 @@ class AuthStorageService {
807
807
  /** Inicia a verificação do login. */
808
808
  startLoginCheck() {
809
809
  if (!this.__isCheckingAuth) {
810
- this.checkAuthentication().subscribe((isLoggedIn) => {
811
- if (isLoggedIn) {
810
+ this.checkAuthentication().subscribe((res) => {
811
+ if (res.isLoggedIn) {
812
812
  // ERICK: Chamada do método custom movida para cá para chamar uma única vez ao invés de se repetir a cada validação do token no método reCheckLogin,
813
813
  // visto que o método storageInitializeAutoStorage tem como objetivo realizar inicializações diversas quando o Login é executado via Pré Portal,
814
814
  // e não há necessidade de repetir essas inicializações a cada verificação do token.
@@ -820,10 +820,14 @@ class AuthStorageService {
820
820
  }
821
821
  checkAuthentication() {
822
822
  if (!this.__authenticationCheck$) {
823
+ let errorMessage = '';
823
824
  this.__authenticationCheck$ = this.verifyToken()
824
- .pipe(map((response) => !response.Error), catchError(() => {
825
+ .pipe(map((response) => {
826
+ errorMessage = response.ErrorMessage;
827
+ return { error: response.ErrorMessage, isLoggedIn: !response.Error };
828
+ }), catchError((err) => {
825
829
  this.isLoggedInSub.next(false);
826
- return of(false);
830
+ return of({ error: err.error.ErrorMessage, isLoggedIn: false });
827
831
  }), finalize(() => this.__authenticationCheck$ = null), shareReplay({ bufferSize: 1, refCount: true }));
828
832
  }
829
833
  return this.__authenticationCheck$;
@@ -832,7 +836,7 @@ class AuthStorageService {
832
836
  const url = `${this._BASE_VERIFICATION_URL}`;
833
837
  const headers = this._HTTP_HEADERS.set('x-application', this._customEnvironmentService.product);
834
838
  return defer(() => {
835
- this._toastr.info('Validando token do usuário.', 'Aguarde...');
839
+ this._toastr.info('Validando token do usuário.', 'Aguarde...', { disableTimeOut: true, progressBar: true, progressAnimation: 'increasing', closeButton: true });
836
840
  const params = new HttpParams()
837
841
  .set('ip', this.ip)
838
842
  .set('browser', this._ipService.getDataBrowserUser().browser);
@@ -4510,16 +4514,21 @@ i0.ɵɵngDeclareClassMetadataAsync({ minVersion: "18.0.0", version: "19.2.25", n
4510
4514
  }], ctorParameters: () => [{ type: AuthUtilService }, { type: i4.BsModalService }, { type: MenuServicesService }, { type: i3.MessageService }, { type: MeuPerfilService }, { type: i1$1.Router }], propDecorators: null }) });
4511
4515
 
4512
4516
  class AuthGuard {
4513
- constructor(router, authStorageService) {
4514
- this.router = router;
4515
- this.authStorageService = authStorageService;
4517
+ constructor(_router, _authStorage, _message) {
4518
+ this._router = _router;
4519
+ this._authStorage = _authStorage;
4520
+ this._message = _message;
4516
4521
  }
4517
- IsUserAuth() {
4518
- return this.authStorageService.checkAuthentication()
4519
- .pipe(map$1((isLoggedIn) => {
4520
- if (!isLoggedIn || this.authStorageService.isExternalLogin) {
4521
- let login = this.router.parseUrl("/auth/login");
4522
- return login;
4522
+ IsUserAuth(targetUrl = this._router.url) {
4523
+ return this._authStorage.checkAuthentication()
4524
+ .pipe(map$1(({ error, isLoggedIn }) => {
4525
+ if (!isLoggedIn || this._authStorage.isExternalLogin) {
4526
+ const targetPath = targetUrl.split(/[?#]/, 1)[0].replace(/\/+$/, '').toLowerCase();
4527
+ if (error.trim() && (targetPath !== '/auth/login' && targetPath !== '')) {
4528
+ this._router.events.pipe(filter$1((event) => event instanceof NavigationEnd), filter$1(event => event.urlAfterRedirects.split(/[?#]/, 1)[0] === '/auth/login'), take$1(1))
4529
+ .subscribe(() => this._message.showAlertWarning(error));
4530
+ }
4531
+ return this._router.parseUrl('/auth/login');
4523
4532
  }
4524
4533
  return true;
4525
4534
  }));
@@ -4528,21 +4537,21 @@ class AuthGuard {
4528
4537
  if (segments[0]?.path.toLowerCase() === 'auth') {
4529
4538
  return of(false);
4530
4539
  }
4531
- return this.IsUserAuth();
4540
+ return this.IsUserAuth(`/${segments.map(segment => segment.path).join('/')}`);
4532
4541
  }
4533
- canActivate(_route, _state) {
4534
- return this.IsUserAuth();
4542
+ canActivate(_route, state) {
4543
+ return this.IsUserAuth(state.url);
4535
4544
  }
4536
- canLoad(_route) {
4537
- return this.IsUserAuth();
4545
+ canLoad(_route, segments) {
4546
+ return this.IsUserAuth(`/${segments.map(segment => segment.path).join('/')}`);
4538
4547
  }
4539
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthGuard, deps: [{ token: i1$1.Router }, { token: AuthStorageService }], target: i0.ɵɵFactoryTarget.Injectable }); }
4548
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthGuard, deps: [{ token: i1$1.Router }, { token: AuthStorageService }, { token: i3.MessageService }], target: i0.ɵɵFactoryTarget.Injectable }); }
4540
4549
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthGuard, providedIn: 'root' }); }
4541
4550
  }
4542
4551
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthGuard, decorators: [{
4543
4552
  type: Injectable,
4544
4553
  args: [{ providedIn: 'root' }]
4545
- }], ctorParameters: () => [{ type: i1$1.Router }, { type: AuthStorageService }] });
4554
+ }], ctorParameters: () => [{ type: i1$1.Router }, { type: AuthStorageService }, { type: i3.MessageService }] });
4546
4555
 
4547
4556
  class ExternaLoginlGuard {
4548
4557
  constructor(router, authService, authStorageService) {