Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32180583
D15031.1765074610.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D15031.1765074610.diff
View Options
diff --git a/lib/backup/user-data-restore-context.js b/lib/backup/user-data-restore-context.js
--- a/lib/backup/user-data-restore-context.js
+++ b/lib/backup/user-data-restore-context.js
@@ -15,7 +15,6 @@
import type { RestoreUserDataStep } from '../types/backup-types.js';
import { restoreUserDataSteps } from '../types/backup-types.js';
import { databaseIdentifier } from '../types/database-identifier-types.js';
-import type { IdentityAuthResult } from '../types/identity-service-types.js';
import type { QRAuthBackupData } from '../types/tunnelbroker/qr-code-auth-message-types.js';
import { getConfig } from '../utils/config.js';
import { BackupIsNewerError } from '../utils/errors.js';
@@ -24,8 +23,9 @@
type UserDataRestoreContextType = {
+userDataRestore: (
+ userID: string,
+ accessToken: string,
backupData: ?QRAuthBackupData,
- identityAuthResult: ?IdentityAuthResult,
) => Promise<void>,
+isRestoring: boolean,
};
@@ -47,8 +47,9 @@
const executeRestoreUserData = React.useCallback(
async (
+ userID: string,
+ accessToken: string,
backupData: ?QRAuthBackupData,
- identityAuthResult: ?IdentityAuthResult,
) => {
const { sqliteAPI } = getConfig();
@@ -87,12 +88,13 @@
// 1. Download database and apply all logs
if (startStepIndex === 0) {
invariant(
- backupData && identityAuthResult,
- 'backupData and identityAuthResult should exist when starting from scratch',
+ backupData,
+ 'backupData should exist when starting from scratch',
);
const restoreUserDataPromise = sqliteAPI.restoreUserData(
backupData,
- identityAuthResult,
+ userID,
+ accessToken,
);
void dispatchActionPromise(
restoreUserDataStepActionTypes,
@@ -245,7 +247,7 @@
// 6. Populate store
const clientDBStore = await sqliteAPI.getClientDBStore(
databaseIdentifier.MAIN,
- identityAuthResult?.userID,
+ userID,
);
dispatch({
@@ -258,8 +260,9 @@
const userDataRestore = React.useCallback(
async (
+ userID: string,
+ accessToken: string,
backupData: ?QRAuthBackupData,
- identityAuthResult: ?IdentityAuthResult,
): Promise<void> => {
if (restorePromiseRef.current) {
return restorePromiseRef.current;
@@ -267,7 +270,7 @@
const promise = (async () => {
try {
- await executeRestoreUserData(backupData, identityAuthResult);
+ await executeRestoreUserData(userID, accessToken, backupData);
} finally {
restorePromiseRef.current = null;
}
diff --git a/lib/components/secondary-device-qr-auth-context-provider.react.js b/lib/components/secondary-device-qr-auth-context-provider.react.js
--- a/lib/components/secondary-device-qr-auth-context-provider.react.js
+++ b/lib/components/secondary-device-qr-auth-context-provider.react.js
@@ -204,7 +204,11 @@
if (!backupData) {
throw new Error('Missing backupData');
}
- await userDataRestore(backupData, identityAuthResult);
+ await userDataRestore(
+ identityAuthResult.userID,
+ identityAuthResult.accessToken,
+ backupData,
+ );
} catch (e) {
addLog(
'Error when restoring User Data',
diff --git a/lib/handlers/restore-backup-handler.react.js b/lib/handlers/restore-backup-handler.react.js
--- a/lib/handlers/restore-backup-handler.react.js
+++ b/lib/handlers/restore-backup-handler.react.js
@@ -12,10 +12,18 @@
// We want this handler to be executed only once
const executed = React.useRef(false);
const restoreBackupState = useSelector(state => state.restoreBackupState);
+ const userID = useSelector(state => state.currentUserInfo?.id);
+ const accessToken = useSelector(state => state.commServicesAccessToken);
const { userDataRestore } = useUserDataRestoreContext();
React.useEffect(() => {
- if (!fullBackupSupport || !persistedStateLoaded || executed.current) {
+ if (
+ !fullBackupSupport ||
+ !persistedStateLoaded ||
+ executed.current ||
+ !userID ||
+ !accessToken
+ ) {
return;
}
if (
@@ -25,9 +33,15 @@
return;
}
- void userDataRestore();
+ void userDataRestore(userID, accessToken);
executed.current = true;
- }, [persistedStateLoaded, restoreBackupState.status, userDataRestore]);
+ }, [
+ accessToken,
+ persistedStateLoaded,
+ restoreBackupState.status,
+ userDataRestore,
+ userID,
+ ]);
return null;
}
diff --git a/lib/tunnelbroker/use-peer-to-peer-message-handler.js b/lib/tunnelbroker/use-peer-to-peer-message-handler.js
--- a/lib/tunnelbroker/use-peer-to-peer-message-handler.js
+++ b/lib/tunnelbroker/use-peer-to-peer-message-handler.js
@@ -98,7 +98,6 @@
const processDMOperation = useProcessDMOperation();
const { userDataRestore } = useUserDataRestoreContext();
const restoreBackupState = useSelector(state => state.restoreBackupState);
- const username = useSelector(state => state.currentUserInfo?.username);
return React.useCallback(
async (
@@ -202,15 +201,11 @@
return;
}
- if (!username || !accessToken) {
+ if (!accessToken) {
return;
}
- await userDataRestore(backupData, {
- userID,
- accessToken,
- username,
- });
+ await userDataRestore(userID, accessToken, backupData);
await sqliteAPI.removeInboundP2PMessages([messageID]);
} else {
@@ -230,7 +225,6 @@
restoreBackupState.status,
runDeviceListUpdate,
userDataRestore,
- username,
],
);
}
diff --git a/lib/types/sqlite-types.js b/lib/types/sqlite-types.js
--- a/lib/types/sqlite-types.js
+++ b/lib/types/sqlite-types.js
@@ -2,7 +2,6 @@
import type { DatabaseIdentifier } from './database-identifier-types.js';
import type { StoredHolders } from './holder-types.js';
-import type { IdentityAuthResult } from './identity-service-types.js';
import type { ClientDBMessageInfo } from './message-types.js';
import type { ClientStore, StoreOperations } from './store-ops-types.js';
import type { QRAuthBackupData } from './tunnelbroker/qr-code-auth-message-types.js';
@@ -104,7 +103,8 @@
// backup
+restoreUserData: (
qrAuthBackupData: QRAuthBackupData,
- identityAuthResult: IdentityAuthResult,
+ userID: string,
+ accessToken: string,
) => Promise<void>,
+migrateBackupSchema: () => Promise<void>,
+copyContentFromBackupDatabase: () => Promise<void>,
diff --git a/native/account/restore.js b/native/account/restore.js
--- a/native/account/restore.js
+++ b/native/account/restore.js
@@ -219,7 +219,11 @@
throw new Error('Missing identityAuthResult');
}
const backupData = await commCoreModule.getQRAuthBackupData();
- await userDataRestore(backupData, identityAuthResult);
+ await userDataRestore(
+ identityAuthResult.userID,
+ identityAuthResult.accessToken,
+ backupData,
+ );
} catch (error) {
const messageForException = getMessageForException(error);
addLog(
diff --git a/web/database/sqlite-api.js b/web/database/sqlite-api.js
--- a/web/database/sqlite-api.js
+++ b/web/database/sqlite-api.js
@@ -8,7 +8,6 @@
ClientDBHolderItem,
StoredHolders,
} from 'lib/types/holder-types.js';
-import type { IdentityAuthResult } from 'lib/types/identity-service-types.js';
import type { ClientDBMessageInfo } from 'lib/types/message-types.js';
import type {
SQLiteAPI,
@@ -260,10 +259,10 @@
//backup
async restoreUserData(
qrAuthBackupData: QRAuthBackupData,
- identityAuthResult: IdentityAuthResult,
+ userID: string,
+ accessToken: string,
): Promise<void> {
const { backupID, backupDataKey, backupLogDataKey } = qrAuthBackupData;
- const { userID, accessToken } = identityAuthResult;
const [deviceID, sharedWorker] = await Promise.all([
getContentSigningKey(),
getCommSharedWorker(),
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 7, 2:30 AM (21 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5842157
Default Alt Text
D15031.1765074610.diff (7 KB)
Attached To
Mode
D15031: [lib][native][web] update `UserDataRestoreProvider` to make `userID` param mandatory
Attached
Detach File
Event Timeline
Log In to Comment