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
  *
@@ -4430,11 +4430,16 @@
4430
4430
  const origUserId = currentUser.userId;
4431
4431
  if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
4432
4432
  const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
4433
- if (licenseStatus === 'ok' && currentUser.accessToken && (!currentUser.accessTokenExpiration || currentUser.accessTokenExpiration.getTime() > Date.now())) {
4433
+ if (licenseStatus === 'ok' &&
4434
+ currentUser.accessToken &&
4435
+ (!currentUser.accessTokenExpiration ||
4436
+ currentUser.accessTokenExpiration.getTime() > Date.now())) {
4434
4437
  // Already authenticated according to given hints. And license is valid.
4435
4438
  return false;
4436
4439
  }
4437
- if (currentUser.refreshToken && (!currentUser.refreshTokenExpiration || currentUser.refreshTokenExpiration.getTime() > Date.now())) {
4440
+ if (currentUser.refreshToken &&
4441
+ (!currentUser.refreshTokenExpiration ||
4442
+ currentUser.refreshTokenExpiration.getTime() > Date.now())) {
4438
4443
  // Refresh the token
4439
4444
  yield loadAccessToken(db);
4440
4445
  return false;
@@ -4446,7 +4451,8 @@
4446
4451
  lastLogin: new Date(0),
4447
4452
  });
4448
4453
  yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
4449
- if (origUserId !== UNAUTHORIZED_USER.userId && context.userId !== origUserId) {
4454
+ if (origUserId !== UNAUTHORIZED_USER.userId &&
4455
+ context.userId !== origUserId) {
4450
4456
  // User was logged in before, but now logged in as another user.
4451
4457
  yield logout(db);
4452
4458
  }
@@ -4465,7 +4471,7 @@
4465
4471
  yield setCurrentUser(db, context);
4466
4472
  // Make sure to resync as the new login will be authorized
4467
4473
  // for new realms.
4468
- triggerSync(db, "pull");
4474
+ triggerSync(db, 'pull');
4469
4475
  return context.userId !== origUserId;
4470
4476
  });
4471
4477
  }
@@ -6302,7 +6308,7 @@
6302
6308
  const syncComplete = new rxjs.Subject();
6303
6309
  dexie.cloud = {
6304
6310
  // @ts-ignore
6305
- version: "4.0.3",
6311
+ version: "4.0.4",
6306
6312
  options: Object.assign({}, DEFAULT_OPTIONS),
6307
6313
  schema: null,
6308
6314
  get currentUserId() {
@@ -6533,7 +6539,10 @@
6533
6539
  // HERE: If requireAuth, do athentication now.
6534
6540
  let changedUser = false;
6535
6541
  if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
6536
- changedUser = yield login(db);
6542
+ const user = yield db.getCurrentUser();
6543
+ if (!user.isLoggedIn) {
6544
+ changedUser = yield login(db);
6545
+ }
6537
6546
  }
6538
6547
  if (localSyncWorker)
6539
6548
  localSyncWorker.stop();
@@ -6579,7 +6588,7 @@
6579
6588
  }
6580
6589
  }
6581
6590
  // @ts-ignore
6582
- dexieCloud.version = "4.0.3";
6591
+ dexieCloud.version = "4.0.4";
6583
6592
  Dexie.Cloud = dexieCloud;
6584
6593
 
6585
6594
  // In case the SW lives for a while, let it reuse already opened connections: