@rdlabo/ionic-angular-kit 21.4.8 → 21.4.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.
@@ -1262,9 +1262,14 @@ class KitAuthAccessService {
1262
1262
  grantLocal() {
1263
1263
  this.#publish('local');
1264
1264
  }
1265
- /** Publish a remotely authenticated session. */
1265
+ /**
1266
+ * Publish a remotely authenticated session and return the lease that owns that publication.
1267
+ *
1268
+ * The revision is fixed before synchronous `mode$` subscribers run. A subscriber that starts a
1269
+ * newer logout or identity transition therefore makes the returned lease stale.
1270
+ */
1266
1271
  grantRemote() {
1267
- this.#publish('remote');
1272
+ return this.#publish('remote');
1268
1273
  }
1269
1274
  /** Revoke both local and remote access. */
1270
1275
  clear() {
@@ -1272,7 +1277,9 @@ class KitAuthAccessService {
1272
1277
  }
1273
1278
  #publish(mode) {
1274
1279
  this.#revision += 1;
1280
+ const revision = this.#revision;
1275
1281
  this.#mode.next(mode);
1282
+ return { isCurrent: () => this.#revision === revision };
1276
1283
  }
1277
1284
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: KitAuthAccessService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1278
1285
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: KitAuthAccessService, providedIn: 'root' }); }
@@ -1377,8 +1384,8 @@ class KitAuthRecoveryService {
1377
1384
  if (this.#destroyed || !recovery || this.#access.mode !== 'local')
1378
1385
  return;
1379
1386
  const lease = this.#access.beginTransition();
1380
- let expectedRevision = this.#access.revision;
1381
- const isCurrent = () => this.#access.revision === expectedRevision;
1387
+ let currentLease = lease;
1388
+ const isCurrent = () => currentLease.isCurrent();
1382
1389
  try {
1383
1390
  const result = await recovery.reauthenticate(lease);
1384
1391
  if (this.#destroyed || !isCurrent() || this.#access.mode !== 'local')
@@ -1395,9 +1402,10 @@ class KitAuthRecoveryService {
1395
1402
  return;
1396
1403
  }
1397
1404
  this.#clearRetry();
1398
- this.#access.grantRemote();
1399
- expectedRevision = this.#access.revision;
1400
- await result.resume();
1405
+ currentLease = this.#access.grantRemote();
1406
+ if (!currentLease.isCurrent())
1407
+ return;
1408
+ await result.resume(currentLease);
1401
1409
  }
1402
1410
  catch (error) {
1403
1411
  if (this.#destroyed || !isCurrent())
@@ -1627,13 +1635,14 @@ const kitRequireAuthorizedGuard = (_route, state) => {
1627
1635
  if (isRemoteAccessActivation(result)) {
1628
1636
  if (!(await result.activate(lease)) || !lease.isCurrent())
1629
1637
  return false;
1630
- access.grantRemote();
1631
- const remoteRevision = access.revision;
1638
+ const resumeLease = access.grantRemote();
1639
+ if (!resumeLease.isCurrent())
1640
+ return false;
1632
1641
  try {
1633
- await result.resume();
1642
+ await result.resume(resumeLease);
1634
1643
  }
1635
1644
  catch (error) {
1636
- if (access.revision !== remoteRevision)
1645
+ if (!resumeLease.isCurrent())
1637
1646
  return false;
1638
1647
  if (isExplicitAuthDenial(error)) {
1639
1648
  access.clear();
@@ -1642,7 +1651,7 @@ const kitRequireAuthorizedGuard = (_route, state) => {
1642
1651
  if (!isUnavailableError?.(error))
1643
1652
  throw error;
1644
1653
  }
1645
- return access.revision === remoteRevision;
1654
+ return resumeLease.isCurrent();
1646
1655
  }
1647
1656
  if (result === true)
1648
1657
  access.grantRemote();