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
  *
@@ -2628,11 +2628,16 @@ function login(db, hints) {
2628
2628
  const origUserId = currentUser.userId;
2629
2629
  if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
2630
2630
  const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
2631
- if (licenseStatus === 'ok' && currentUser.accessToken && (!currentUser.accessTokenExpiration || currentUser.accessTokenExpiration.getTime() > Date.now())) {
2631
+ if (licenseStatus === 'ok' &&
2632
+ currentUser.accessToken &&
2633
+ (!currentUser.accessTokenExpiration ||
2634
+ currentUser.accessTokenExpiration.getTime() > Date.now())) {
2632
2635
  // Already authenticated according to given hints. And license is valid.
2633
2636
  return false;
2634
2637
  }
2635
- if (currentUser.refreshToken && (!currentUser.refreshTokenExpiration || currentUser.refreshTokenExpiration.getTime() > Date.now())) {
2638
+ if (currentUser.refreshToken &&
2639
+ (!currentUser.refreshTokenExpiration ||
2640
+ currentUser.refreshTokenExpiration.getTime() > Date.now())) {
2636
2641
  // Refresh the token
2637
2642
  yield loadAccessToken(db);
2638
2643
  return false;
@@ -2644,7 +2649,8 @@ function login(db, hints) {
2644
2649
  lastLogin: new Date(0),
2645
2650
  });
2646
2651
  yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
2647
- if (origUserId !== UNAUTHORIZED_USER.userId && context.userId !== origUserId) {
2652
+ if (origUserId !== UNAUTHORIZED_USER.userId &&
2653
+ context.userId !== origUserId) {
2648
2654
  // User was logged in before, but now logged in as another user.
2649
2655
  yield logout(db);
2650
2656
  }
@@ -2663,7 +2669,7 @@ function login(db, hints) {
2663
2669
  yield setCurrentUser(db, context);
2664
2670
  // Make sure to resync as the new login will be authorized
2665
2671
  // for new realms.
2666
- triggerSync(db, "pull");
2672
+ triggerSync(db, 'pull');
2667
2673
  return context.userId !== origUserId;
2668
2674
  });
2669
2675
  }
@@ -6306,7 +6312,7 @@ function dexieCloud(dexie) {
6306
6312
  const syncComplete = new Subject();
6307
6313
  dexie.cloud = {
6308
6314
  // @ts-ignore
6309
- version: "4.0.3",
6315
+ version: "4.0.4",
6310
6316
  options: Object.assign({}, DEFAULT_OPTIONS),
6311
6317
  schema: null,
6312
6318
  get currentUserId() {
@@ -6537,7 +6543,10 @@ function dexieCloud(dexie) {
6537
6543
  // HERE: If requireAuth, do athentication now.
6538
6544
  let changedUser = false;
6539
6545
  if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
6540
- changedUser = yield login(db);
6546
+ const user = yield db.getCurrentUser();
6547
+ if (!user.isLoggedIn) {
6548
+ changedUser = yield login(db);
6549
+ }
6541
6550
  }
6542
6551
  if (localSyncWorker)
6543
6552
  localSyncWorker.stop();
@@ -6583,7 +6592,7 @@ function dexieCloud(dexie) {
6583
6592
  }
6584
6593
  }
6585
6594
  // @ts-ignore
6586
- dexieCloud.version = "4.0.3";
6595
+ dexieCloud.version = "4.0.4";
6587
6596
  Dexie.Cloud = dexieCloud;
6588
6597
 
6589
6598
  export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId, resolveText };