feat: Fix WebSocket connection issues after account registration by ensuring connection before authentication

This commit is contained in:
k1ngsterr1
2026-01-11 16:19:44 +05:00
parent 5f21f120f1
commit 70ed7fbc6e
4 changed files with 89 additions and 2 deletions

View File

@@ -175,7 +175,13 @@ class AuthStateManager(
loadAccounts()
// Step 8: Authenticate with protocol
// Step 8: Connect and authenticate with protocol
Log.d(TAG, "🌐 Connecting to protocol server...")
ProtocolManager.connect()
// Give WebSocket time to connect before authenticating
kotlinx.coroutines.delay(500)
Log.d(TAG, "🌐 Authenticating with protocol server...")
ProtocolManager.authenticate(keyPair.publicKey, privateKeyHash)
@@ -236,7 +242,13 @@ class AuthStateManager(
status = AuthStatus.Authenticated(decryptedAccount)
)}
// Authenticate with protocol
// Connect and authenticate with protocol
Log.d(TAG, "🌐 Connecting to protocol server...")
ProtocolManager.connect()
// Give WebSocket time to connect before authenticating
kotlinx.coroutines.delay(500)
Log.d(TAG, "🌐 Authenticating with protocol server...")
ProtocolManager.authenticate(decryptedAccount.publicKey, decryptedAccount.privateKeyHash)

View File

@@ -497,6 +497,9 @@ fun SetPasswordScreen(
// 🔌 Connect to server and authenticate
val privateKeyHash = CryptoManager.generatePrivateKeyHash(keyPair.privateKey)
Log.d("SetPasswordScreen", "🔌 Connecting to server...")
ProtocolManager.connect()
// Give WebSocket time to connect before authenticating
kotlinx.coroutines.delay(500)
ProtocolManager.authenticate(keyPair.publicKey, privateKeyHash)
onAccountCreated()

View File

@@ -581,6 +581,9 @@ fun UnlockScreen(
// Connect to server and authenticate
Log.d("UnlockScreen", "Connecting to server...")
ProtocolManager.connect()
// Give WebSocket time to connect before authenticating
kotlinx.coroutines.delay(500)
ProtocolManager.authenticate(account.publicKey, privateKeyHash)
accountManager.setCurrentAccount(account.publicKey)