From 5eccd1412002da76ef731ac8caa51ac2190bab83 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 11 Jun 2019 12:02:14 +0100 Subject: [PATCH 1/3] Fix registration after fail-fast The lineness checks meant that we could no longer assume we always had a matrix client, so don't assume we do. Fixes https://github.com/vector-im/riot-web/issues/10011 --- .../structures/auth/Registration.js | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index 7dd24b550b..8188dbb3f7 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -88,6 +88,10 @@ module.exports = React.createClass({ serverIsAlive: true, serverErrorIsFatal: false, serverDeadError: "", + + // Our matrix client - part of state because we can't render the UI auth + // component without it. + matrixClient: null, }; }, @@ -159,6 +163,9 @@ module.exports = React.createClass({ _replaceClient: async function(serverConfig) { this.setState({ errorText: null, + // busy while we do liveness check (we need to avoid trying to render + // the UI auth component while we don't have a matrix client) + busy: true, }); if (!serverConfig) serverConfig = this.props.serverConfig; @@ -177,10 +184,13 @@ module.exports = React.createClass({ } const {hsUrl, isUrl} = serverConfig; - this._matrixClient = Matrix.createClient({ - baseUrl: hsUrl, - idBaseUrl: isUrl, + this.setState({ + matrixClient: Matrix.createClient({ + baseUrl: hsUrl, + idBaseUrl: isUrl, + }), }); + this.setState({busy: false}); try { await this._makeRegisterRequest({}); // This should never succeed since we specified an empty @@ -213,14 +223,14 @@ module.exports = React.createClass({ }, _requestEmailToken: function(emailAddress, clientSecret, sendAttempt, sessionId) { - return this._matrixClient.requestRegisterEmailToken( + return this.state.matrixClient.requestRegisterEmailToken( emailAddress, clientSecret, sendAttempt, this.props.makeRegistrationUrl({ client_secret: clientSecret, - hs_url: this._matrixClient.getHomeserverUrl(), - is_url: this._matrixClient.getIdentityServerUrl(), + hs_url: this.state.matrixClient.getHomeserverUrl(), + is_url: this.state.matrixClient.getIdentityServerUrl(), session_id: sessionId, }), ); @@ -278,8 +288,8 @@ module.exports = React.createClass({ const cli = await this.props.onLoggedIn({ userId: response.user_id, deviceId: response.device_id, - homeserverUrl: this._matrixClient.getHomeserverUrl(), - identityServerUrl: this._matrixClient.getIdentityServerUrl(), + homeserverUrl: this.state.matrixClient.getHomeserverUrl(), + identityServerUrl: this.state.matrixClient.getIdentityServerUrl(), accessToken: response.access_token, }); @@ -348,7 +358,7 @@ module.exports = React.createClass({ msisdn: true, } : {}; - return this._matrixClient.register( + return this.state.matrixClient.register( this.state.formVals.username, this.state.formVals.password, undefined, // session id: included in the auth dict already @@ -433,9 +443,9 @@ module.exports = React.createClass({ const Spinner = sdk.getComponent('elements.Spinner'); const RegistrationForm = sdk.getComponent('auth.RegistrationForm'); - if (this.state.doingUIAuth) { + if (this.state.matrixClient && this.state.doingUIAuth) { return Date: Tue, 11 Jun 2019 12:10:44 +0100 Subject: [PATCH 2/3] Don't show spinner once liveness check has failed We're not doing anything at that point so it's a lie --- src/components/structures/auth/Registration.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index 8188dbb3f7..dbcd01366c 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -177,7 +177,10 @@ module.exports = React.createClass({ ); this.setState({serverIsAlive: true}); } catch (e) { - this.setState(AutoDiscoveryUtils.authComponentStateForError(e, "register")); + this.setState({ + busy: false, + ...AutoDiscoveryUtils.authComponentStateForError(e, "register"), + }); if (this.state.serverErrorIsFatal) { return; // Server is dead - do not continue. } @@ -455,6 +458,8 @@ module.exports = React.createClass({ emailSid={this.props.idSid} poll={true} />; + } else if (!this.state.matrixClient && !this.state.busy) { + return null; } else if (this.state.busy || !this.state.flows) { return
From 7602d7672309844bb04f3201b7e4323bc1e84096 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 11 Jun 2019 13:16:49 +0100 Subject: [PATCH 3/3] fix test --- test/components/structures/auth/Registration-test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/components/structures/auth/Registration-test.js b/test/components/structures/auth/Registration-test.js index 6914ed71d7..6a8b35fbc0 100644 --- a/test/components/structures/auth/Registration-test.js +++ b/test/components/structures/auth/Registration-test.js @@ -69,9 +69,11 @@ describe('Registration', function() { const root = render(); - // Set non-empty flows to get past the loading spinner + // Set non-empty flow & matrixClient to get past the loading spinner root.setState({ flows: [], + matrixClient: {}, + busy: false, }); const form = ReactTestUtils.findRenderedComponentWithType(