diff --git a/native/backup/backup-handler.js b/native/backup/backup-handler.js --- a/native/backup/backup-handler.js +++ b/native/backup/backup-handler.js @@ -125,41 +125,41 @@ const deviceListIsSigned = currentIdentityUserState.currentDeviceList.curPrimarySignature; - // Early return is safe: - // - in the case of non-primary device, the attempt to upload - // a backup is not needed - // - in the case of a signed device list there is no need - // to perform the migration. - if (!isPrimaryDevice && deviceListIsSigned) { - backupUploadInProgress.current = false; - return; - } + // In case of unsigned device list migration and backup upload is needed. + // Uploading backup in this case is handled by `migrateToNewFlow`. + const shouldDoMigration = usingRestoreFlow && !deviceListIsSigned; - const shouldDoMigration = - usingRestoreFlow && (!latestBackupInfo || !deviceListIsSigned); - if (!shouldDoMigration && !isPrimaryDevice) { + // When this is a primary device and there is no latest backup it + // needs to be updated. This handles cases after restoration + // or after registration. + const shouldCreateUserKeysBackup = isPrimaryDevice && !latestBackupInfo; + + if (!shouldDoMigration && !shouldCreateUserKeysBackup) { backupUploadInProgress.current = false; return; } + try { const promise = (async () => { - if (shouldDoMigration && !deviceListIsSigned) { + if (shouldDoMigration) { if (!currentIdentityUserState) { throw new Error('Missing currentIdentityUserState'); } + // Early return without checking `shouldCreateUserKeysBackup` + // is safe because migration is uploading User Keys backup. return await migrateToNewFlow( userID, deviceID, currentIdentityUserState, ); - } else { - const backupID = await createUserKeysBackup(); - return { - backupID, - timestamp: Date.now(), - }; } + + const backupID = await createUserKeysBackup(); + return { + backupID, + timestamp: Date.now(), + }; })(); void dispatchActionPromise(createUserKeysBackupActionTypes, promise); await promise;