dexie-cloud-addon 4.0.1-beta.57 → 4.0.1-beta.58

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.1-beta.57, Wed Feb 14 2024
11
+ * Version 4.0.1-beta.58, Tue Feb 20 2024
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -4391,11 +4391,16 @@ function login(db, hints) {
4391
4391
  const origUserId = currentUser.userId;
4392
4392
  if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
4393
4393
  const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
4394
- if (licenseStatus === 'ok' && currentUser.accessToken && (!currentUser.accessTokenExpiration || currentUser.accessTokenExpiration.getTime() > Date.now())) {
4394
+ if (licenseStatus === 'ok' &&
4395
+ currentUser.accessToken &&
4396
+ (!currentUser.accessTokenExpiration ||
4397
+ currentUser.accessTokenExpiration.getTime() > Date.now())) {
4395
4398
  // Already authenticated according to given hints. And license is valid.
4396
4399
  return false;
4397
4400
  }
4398
- if (currentUser.refreshToken && (!currentUser.refreshTokenExpiration || currentUser.refreshTokenExpiration.getTime() > Date.now())) {
4401
+ if (currentUser.refreshToken &&
4402
+ (!currentUser.refreshTokenExpiration ||
4403
+ currentUser.refreshTokenExpiration.getTime() > Date.now())) {
4399
4404
  // Refresh the token
4400
4405
  yield loadAccessToken(db);
4401
4406
  return false;
@@ -4407,7 +4412,8 @@ function login(db, hints) {
4407
4412
  lastLogin: new Date(0),
4408
4413
  });
4409
4414
  yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
4410
- if (origUserId !== UNAUTHORIZED_USER.userId && context.userId !== origUserId) {
4415
+ if (origUserId !== UNAUTHORIZED_USER.userId &&
4416
+ context.userId !== origUserId) {
4411
4417
  // User was logged in before, but now logged in as another user.
4412
4418
  yield logout(db);
4413
4419
  }
@@ -4426,7 +4432,7 @@ function login(db, hints) {
4426
4432
  yield setCurrentUser(db, context);
4427
4433
  // Make sure to resync as the new login will be authorized
4428
4434
  // for new realms.
4429
- triggerSync(db, "pull");
4435
+ triggerSync(db, 'pull');
4430
4436
  return context.userId !== origUserId;
4431
4437
  });
4432
4438
  }
@@ -6257,7 +6263,7 @@ function dexieCloud(dexie) {
6257
6263
  const syncComplete = new Subject();
6258
6264
  dexie.cloud = {
6259
6265
  // @ts-ignore
6260
- version: "4.0.1-beta.57",
6266
+ version: "4.0.1-beta.58",
6261
6267
  options: Object.assign({}, DEFAULT_OPTIONS),
6262
6268
  schema: null,
6263
6269
  get currentUserId() {
@@ -6488,7 +6494,10 @@ function dexieCloud(dexie) {
6488
6494
  // HERE: If requireAuth, do athentication now.
6489
6495
  let changedUser = false;
6490
6496
  if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
6491
- changedUser = yield login(db);
6497
+ const user = yield db.getCurrentUser();
6498
+ if (!user.isLoggedIn) {
6499
+ changedUser = yield login(db);
6500
+ }
6492
6501
  }
6493
6502
  if (localSyncWorker)
6494
6503
  localSyncWorker.stop();
@@ -6534,7 +6543,7 @@ function dexieCloud(dexie) {
6534
6543
  }
6535
6544
  }
6536
6545
  // @ts-ignore
6537
- dexieCloud.version = "4.0.1-beta.57";
6546
+ dexieCloud.version = "4.0.1-beta.58";
6538
6547
  Dexie.Cloud = dexieCloud;
6539
6548
 
6540
6549
  // In case the SW lives for a while, let it reuse already opened connections: