From 5926e277c485d7833c6b75b52ccdbfc33db6034e Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 16 Jan 2020 11:52:02 +0000 Subject: [PATCH] Avoid logged in event race --- src/components/structures/MatrixChat.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index edc0501086..c59c44ebd8 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -1820,12 +1820,9 @@ export default createReactClass({ }, async onUserCompletedLoginFlow(credentials) { - // Create and start the client in the background - Lifecycle.setLoggedIn(credentials); - // Wait for the client to be logged in (but not started) // which is enough to ask the server about account data. - await new Promise(resolve => { + const loggedIn = new Promise(resolve => { const actionHandlerRef = dis.register(payload => { if (payload.action !== "on_logged_in") { return; @@ -1835,6 +1832,10 @@ export default createReactClass({ }); }); + // Create and start the client in the background + Lifecycle.setLoggedIn(credentials); + await loggedIn; + const cli = MatrixClientPeg.get(); // We're checking `isCryptoAvailable` here instead of `isCryptoEnabled` // because the client hasn't been started yet.