mirror of https://github.com/vector-im/riot-web
Merge pull request #3090 from matrix-org/dbkr/registration_matrixclient_sometimes_isnt_there
Fix registration after fail-fastpull/21833/head
commit
acb5372b7c
|
@ -88,6 +88,10 @@ module.exports = React.createClass({
|
||||||
serverIsAlive: true,
|
serverIsAlive: true,
|
||||||
serverErrorIsFatal: false,
|
serverErrorIsFatal: false,
|
||||||
serverDeadError: "",
|
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) {
|
_replaceClient: async function(serverConfig) {
|
||||||
this.setState({
|
this.setState({
|
||||||
errorText: null,
|
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;
|
if (!serverConfig) serverConfig = this.props.serverConfig;
|
||||||
|
|
||||||
|
@ -170,17 +177,23 @@ module.exports = React.createClass({
|
||||||
);
|
);
|
||||||
this.setState({serverIsAlive: true});
|
this.setState({serverIsAlive: true});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.setState(AutoDiscoveryUtils.authComponentStateForError(e, "register"));
|
this.setState({
|
||||||
|
busy: false,
|
||||||
|
...AutoDiscoveryUtils.authComponentStateForError(e, "register"),
|
||||||
|
});
|
||||||
if (this.state.serverErrorIsFatal) {
|
if (this.state.serverErrorIsFatal) {
|
||||||
return; // Server is dead - do not continue.
|
return; // Server is dead - do not continue.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const {hsUrl, isUrl} = serverConfig;
|
const {hsUrl, isUrl} = serverConfig;
|
||||||
this._matrixClient = Matrix.createClient({
|
this.setState({
|
||||||
baseUrl: hsUrl,
|
matrixClient: Matrix.createClient({
|
||||||
idBaseUrl: isUrl,
|
baseUrl: hsUrl,
|
||||||
|
idBaseUrl: isUrl,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
this.setState({busy: false});
|
||||||
try {
|
try {
|
||||||
await this._makeRegisterRequest({});
|
await this._makeRegisterRequest({});
|
||||||
// This should never succeed since we specified an empty
|
// This should never succeed since we specified an empty
|
||||||
|
@ -213,14 +226,14 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
_requestEmailToken: function(emailAddress, clientSecret, sendAttempt, sessionId) {
|
_requestEmailToken: function(emailAddress, clientSecret, sendAttempt, sessionId) {
|
||||||
return this._matrixClient.requestRegisterEmailToken(
|
return this.state.matrixClient.requestRegisterEmailToken(
|
||||||
emailAddress,
|
emailAddress,
|
||||||
clientSecret,
|
clientSecret,
|
||||||
sendAttempt,
|
sendAttempt,
|
||||||
this.props.makeRegistrationUrl({
|
this.props.makeRegistrationUrl({
|
||||||
client_secret: clientSecret,
|
client_secret: clientSecret,
|
||||||
hs_url: this._matrixClient.getHomeserverUrl(),
|
hs_url: this.state.matrixClient.getHomeserverUrl(),
|
||||||
is_url: this._matrixClient.getIdentityServerUrl(),
|
is_url: this.state.matrixClient.getIdentityServerUrl(),
|
||||||
session_id: sessionId,
|
session_id: sessionId,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -278,8 +291,8 @@ module.exports = React.createClass({
|
||||||
const cli = await this.props.onLoggedIn({
|
const cli = await this.props.onLoggedIn({
|
||||||
userId: response.user_id,
|
userId: response.user_id,
|
||||||
deviceId: response.device_id,
|
deviceId: response.device_id,
|
||||||
homeserverUrl: this._matrixClient.getHomeserverUrl(),
|
homeserverUrl: this.state.matrixClient.getHomeserverUrl(),
|
||||||
identityServerUrl: this._matrixClient.getIdentityServerUrl(),
|
identityServerUrl: this.state.matrixClient.getIdentityServerUrl(),
|
||||||
accessToken: response.access_token,
|
accessToken: response.access_token,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -348,7 +361,7 @@ module.exports = React.createClass({
|
||||||
msisdn: true,
|
msisdn: true,
|
||||||
} : {};
|
} : {};
|
||||||
|
|
||||||
return this._matrixClient.register(
|
return this.state.matrixClient.register(
|
||||||
this.state.formVals.username,
|
this.state.formVals.username,
|
||||||
this.state.formVals.password,
|
this.state.formVals.password,
|
||||||
undefined, // session id: included in the auth dict already
|
undefined, // session id: included in the auth dict already
|
||||||
|
@ -433,9 +446,9 @@ module.exports = React.createClass({
|
||||||
const Spinner = sdk.getComponent('elements.Spinner');
|
const Spinner = sdk.getComponent('elements.Spinner');
|
||||||
const RegistrationForm = sdk.getComponent('auth.RegistrationForm');
|
const RegistrationForm = sdk.getComponent('auth.RegistrationForm');
|
||||||
|
|
||||||
if (this.state.doingUIAuth) {
|
if (this.state.matrixClient && this.state.doingUIAuth) {
|
||||||
return <InteractiveAuth
|
return <InteractiveAuth
|
||||||
matrixClient={this._matrixClient}
|
matrixClient={this.state.matrixClient}
|
||||||
makeRequest={this._makeRegisterRequest}
|
makeRequest={this._makeRegisterRequest}
|
||||||
onAuthFinished={this._onUIAuthFinished}
|
onAuthFinished={this._onUIAuthFinished}
|
||||||
inputs={this._getUIAuthInputs()}
|
inputs={this._getUIAuthInputs()}
|
||||||
|
@ -445,6 +458,8 @@ module.exports = React.createClass({
|
||||||
emailSid={this.props.idSid}
|
emailSid={this.props.idSid}
|
||||||
poll={true}
|
poll={true}
|
||||||
/>;
|
/>;
|
||||||
|
} else if (!this.state.matrixClient && !this.state.busy) {
|
||||||
|
return null;
|
||||||
} else if (this.state.busy || !this.state.flows) {
|
} else if (this.state.busy || !this.state.flows) {
|
||||||
return <div className="mx_AuthBody_spinner">
|
return <div className="mx_AuthBody_spinner">
|
||||||
<Spinner />
|
<Spinner />
|
||||||
|
|
|
@ -69,9 +69,11 @@ describe('Registration', function() {
|
||||||
|
|
||||||
const root = render();
|
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({
|
root.setState({
|
||||||
flows: [],
|
flows: [],
|
||||||
|
matrixClient: {},
|
||||||
|
busy: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const form = ReactTestUtils.findRenderedComponentWithType(
|
const form = ReactTestUtils.findRenderedComponentWithType(
|
||||||
|
|
Loading…
Reference in New Issue