diff --git a/src/Lifecycle.js b/src/Lifecycle.js index f7579cf3c0e..1fbfe4445e9 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -415,16 +415,18 @@ export function logout() { // Also we sometimes want to re-log in a guest session // if we abort the login - // use settimeout to avoid racing with react unmounting components - // which need a valid matrixclientpeg - setTimeout(()=>{ - onLoggedOut(); - }, 0); - return; + return new Promise((resolve, _reject) => { + // use settimeout to avoid racing with react unmounting components + // which need a valid matrixclientpeg + setTimeout(()=>{ + onLoggedOut(); + resolve(); + }, 0); + }); } _isLoggingOut = true; - MatrixClientPeg.get().logout().then(onLoggedOut, + return MatrixClientPeg.get().logout().then(onLoggedOut, (err) => { // Just throwing an error here is going to be very unhelpful // if you're trying to log out because your server's down and diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 2622a6bf93b..51b834a350f 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -502,15 +502,26 @@ export default React.createClass({ startAnyRegistrationFlow(payload); break; case 'start_registration': - // This starts the full registration flow - this._startRegistration(payload.params || {}); - break; - case 'start_login': - this.setStateForNewView({ - view: VIEWS.LOGIN, + case 'start_login': { + let logoutPromise = Promise.resolve(); + if (payload.params && payload.params.logoutFirst) { + logoutPromise = Lifecycle.logout(); + } + logoutPromise.then(() => { + if (payload.action === "start_login") { + this.setStateForNewView({ + view: VIEWS.LOGIN, + }); + this.notifyNewScreen('login'); + } else if (payload.action === "start_registration") { + // This starts the full registration flow + this._startRegistration(payload.params || {}); + } else { + throw new Error("Unknown action for post-logout"); + } }); - this.notifyNewScreen('login'); break; + } case 'start_post_registration': this.setState({ view: VIEWS.POST_REGISTRATION,