Try fixing initialization

This commit is contained in:
2025-12-03 18:43:16 +03:00
Unverified
parent 10e5417254
commit 4b5de53900
14 changed files with 759 additions and 33 deletions
+34
View File
@@ -120,6 +120,40 @@ export function RegisterForm({ onSwitchMode }: RegisterFormProps) {
try {
await api.user.auth.ensureKeysOnLogin(password, data.token);
// Initialize Signal Protocol after keys are set up (non-blocking)
if (data.user?.id) {
// Run Signal Protocol initialization in background to avoid blocking navigation
(async () => {
try {
const { SignalProtocolService } = await import("@/utils/crypto/signalProtocol");
const { uploadPreKeyBundle, uploadAllPreKeys } = await import("@/core/api/crypto/prekeys");
const { uploadAllSessionsToServer, initializeSessionSync } = await import("@/utils/crypto/sessionSync");
const signalService = new SignalProtocolService(data.user!.id.toString());
await signalService.initialize();
// Initialize session sync (enables automatic upload of new sessions)
initializeSessionSync(data.user!.id.toString(), password, data.token);
// Upload base bundle with one prekey (for backward compatibility)
const bundle = await signalService.getPreKeyBundle();
await uploadPreKeyBundle(bundle, data.token);
// Upload all prekeys for server-side rotation
const baseBundle = await signalService.getBaseBundle();
const prekeys = await signalService.getAllPreKeys();
await uploadAllPreKeys(baseBundle, prekeys, data.token);
// Upload all current sessions to server (backup - will be empty on registration)
await uploadAllSessionsToServer(data.user!.id.toString(), password, data.token);
console.log(`Uploaded ${prekeys.length} prekeys to server`);
} catch (e) {
console.error("Key setup failed:", e);
}
})();
}
} catch (e) {
console.error("Key setup failed:", e);
}