dexie-cloud-addon 4.0.3 → 4.0.4

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.
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * ==========================================================================
10
10
  *
11
- * Version 4.0.3, Sat Apr 13 2024
11
+ * Version 4.0.4, Mon Apr 29 2024
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -2631,11 +2631,16 @@
2631
2631
  const origUserId = currentUser.userId;
2632
2632
  if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
2633
2633
  const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
2634
- if (licenseStatus === 'ok' && currentUser.accessToken && (!currentUser.accessTokenExpiration || currentUser.accessTokenExpiration.getTime() > Date.now())) {
2634
+ if (licenseStatus === 'ok' &&
2635
+ currentUser.accessToken &&
2636
+ (!currentUser.accessTokenExpiration ||
2637
+ currentUser.accessTokenExpiration.getTime() > Date.now())) {
2635
2638
  // Already authenticated according to given hints. And license is valid.
2636
2639
  return false;
2637
2640
  }
2638
- if (currentUser.refreshToken && (!currentUser.refreshTokenExpiration || currentUser.refreshTokenExpiration.getTime() > Date.now())) {
2641
+ if (currentUser.refreshToken &&
2642
+ (!currentUser.refreshTokenExpiration ||
2643
+ currentUser.refreshTokenExpiration.getTime() > Date.now())) {
2639
2644
  // Refresh the token
2640
2645
  yield loadAccessToken(db);
2641
2646
  return false;
@@ -2647,7 +2652,8 @@
2647
2652
  lastLogin: new Date(0),
2648
2653
  });
2649
2654
  yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
2650
- if (origUserId !== UNAUTHORIZED_USER.userId && context.userId !== origUserId) {
2655
+ if (origUserId !== UNAUTHORIZED_USER.userId &&
2656
+ context.userId !== origUserId) {
2651
2657
  // User was logged in before, but now logged in as another user.
2652
2658
  yield logout(db);
2653
2659
  }
@@ -2666,7 +2672,7 @@
2666
2672
  yield setCurrentUser(db, context);
2667
2673
  // Make sure to resync as the new login will be authorized
2668
2674
  // for new realms.
2669
- triggerSync(db, "pull");
2675
+ triggerSync(db, 'pull');
2670
2676
  return context.userId !== origUserId;
2671
2677
  });
2672
2678
  }
@@ -6309,7 +6315,7 @@
6309
6315
  const syncComplete = new rxjs.Subject();
6310
6316
  dexie.cloud = {
6311
6317
  // @ts-ignore
6312
- version: "4.0.3",
6318
+ version: "4.0.4",
6313
6319
  options: Object.assign({}, DEFAULT_OPTIONS),
6314
6320
  schema: null,
6315
6321
  get currentUserId() {
@@ -6540,7 +6546,10 @@
6540
6546
  // HERE: If requireAuth, do athentication now.
6541
6547
  let changedUser = false;
6542
6548
  if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
6543
- changedUser = yield login(db);
6549
+ const user = yield db.getCurrentUser();
6550
+ if (!user.isLoggedIn) {
6551
+ changedUser = yield login(db);
6552
+ }
6544
6553
  }
6545
6554
  if (localSyncWorker)
6546
6555
  localSyncWorker.stop();
@@ -6586,7 +6595,7 @@
6586
6595
  }
6587
6596
  }
6588
6597
  // @ts-ignore
6589
- dexieCloud.version = "4.0.3";
6598
+ dexieCloud.version = "4.0.4";
6590
6599
  Dexie.Cloud = dexieCloud;
6591
6600
 
6592
6601
  exports.default = dexieCloud;