@rdlabo/ionic-angular-kit 22.0.0-5 → 22.0.0-7

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.
@@ -1,13 +1,18 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { inject, Injectable, InjectionToken, makeEnvironmentProviders, Injector, input, computed, HostListener, Directive, ErrorHandler, DestroyRef, provideAppInitializer, Optional, afterNextRender } from '@angular/core';
3
3
  import { Storage } from '@ionic/storage-angular';
4
- import { ModalController, PopoverController, ToastController, AlertController, LoadingController, NavController } from '@ionic/angular';
4
+ import { AlertController } from '@ionic/angular/alert-controller';
5
+ import { ModalController } from '@ionic/angular/modal-controller';
6
+ import { PopoverController } from '@ionic/angular/popover-controller';
7
+ import { ToastController } from '@ionic/angular/toast-controller';
5
8
  import { Capacitor } from '@capacitor/core';
6
9
  import { Keyboard } from '@capacitor/keyboard';
7
10
  import { ImpactStyle, Haptics } from '@capacitor/haptics';
11
+ import { LoadingController } from '@ionic/angular/loading-controller';
8
12
  import { FORM_FIELD } from '@angular/forms/signals';
9
13
  import { BehaviorSubject, Subscription, throwError, of, from, retry, timer, Subject, Observable, startWith } from 'rxjs';
10
14
  import { Router } from '@angular/router';
15
+ import { NavController } from '@ionic/angular/common';
11
16
  import { catchError, map, mergeMap, timeout, tap } from 'rxjs/operators';
12
17
  import { HttpContextToken, HttpErrorResponse, HttpResponse } from '@angular/common/http';
13
18
  import { Network } from '@capacitor/network';
@@ -1514,9 +1519,18 @@ const kitRequireAuthorizedGuard = (_route, state) => {
1514
1519
  const router = inject(Router);
1515
1520
  const navCtrl = inject(NavController);
1516
1521
  const access = inject(KitAuthAccessService);
1522
+ const errorHandler = inject(ErrorHandler);
1517
1523
  const lease = access.beginTransition({ suspendRemote: true });
1518
- const redirectUnauthorized = () => {
1519
- if (!lease.isCurrent())
1524
+ const reportError = (error) => {
1525
+ try {
1526
+ errorHandler.handleError(error);
1527
+ }
1528
+ catch {
1529
+ // Error reporting must not create an unhandled background rejection.
1530
+ }
1531
+ };
1532
+ const redirectUnauthorized = (currentLease = lease) => {
1533
+ if (!currentLease.isCurrent())
1520
1534
  return false;
1521
1535
  access.clear();
1522
1536
  navCtrl.setDirection('root');
@@ -1554,17 +1568,33 @@ const kitRequireAuthorizedGuard = (_route, state) => {
1554
1568
  if (!resumeLease.isCurrent())
1555
1569
  return false;
1556
1570
  const resume = async () => result.resume(resumeLease);
1557
- await resume().catch((error) => {
1571
+ const handleResumeError = (error) => {
1558
1572
  if (!resumeLease.isCurrent())
1559
1573
  return;
1560
1574
  if (isExplicitAuthDenial(error)) {
1575
+ if (result.resumeMode === 'background') {
1576
+ redirectUnauthorized(resumeLease);
1577
+ reportError(error);
1578
+ return;
1579
+ }
1561
1580
  access.clear();
1562
1581
  throw error;
1563
1582
  }
1564
1583
  if (!isUnavailableError?.(error))
1565
1584
  throw error;
1566
- return;
1567
- });
1585
+ };
1586
+ if (result.resumeMode === 'background') {
1587
+ void resume().catch((error) => {
1588
+ try {
1589
+ handleResumeError(error);
1590
+ }
1591
+ catch (unhandledError) {
1592
+ reportError(unhandledError);
1593
+ }
1594
+ });
1595
+ return resumeLease.isCurrent();
1596
+ }
1597
+ await resume().catch(handleResumeError);
1568
1598
  return resumeLease.isCurrent();
1569
1599
  }
1570
1600
  if (result === true)