From 498ea53995db4d8c56145ad20433b093062f3b97 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 14 Jun 2017 10:53:48 +0100 Subject: [PATCH] Don't create a guest login if user went to /login This fixes an unintuitive behaviour where, if you follow a link to riot.im/app/#/login, we take you to the login page, but not before we've registered a guest account (or restarted the MatrixClient with the stored creds). This actually ends up simplifying some of the startup dance, as we special-case the registration flows earlier on. --- src/Lifecycle.js | 11 ----------- src/components/structures/MatrixChat.js | 24 ++++++++++++++++-------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 9b806ba8b7..338341f403 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -35,9 +35,6 @@ import { _t } from './languageHandler'; * Called at startup, to attempt to build a logged-in Matrix session. It tries * a number of things: * - * 0. if it looks like we are in the middle of a registration process, it does - * nothing. - * * 1. if we have a loginToken in the (real) query params, it uses that to log * in. * @@ -80,14 +77,6 @@ export function loadSession(opts) { const guestIsUrl = opts.guestIsUrl; const defaultDeviceDisplayName = opts.defaultDeviceDisplayName; - if (fragmentQueryParams.client_secret && fragmentQueryParams.sid) { - // this happens during email validation: the email contains a link to the - // IS, which in turn redirects back to vector. We let MatrixChat create a - // Registration component which completes the next stage of registration. - console.log("Not registering as guest: registration already in progress."); - return q(); - } - if (!guestHsUrl) { console.warn("Cannot enable guest access: can't determine HS URL to use"); enableGuest = false; diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 50a7c69855..ed1cd183a7 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -269,6 +269,21 @@ module.exports = React.createClass({ Lifecycle.initRtsClient(this.props.config.teamServerConfig.teamServerURL); } + // if the user has followed a login or register link, don't reanimate + // the old creds, but rather go straight to the relevant page + + const firstScreen = this.state.screenAfterLogin ? + this.state.screenAfterLogin.screen : null; + + if (firstScreen === 'login' || + firstScreen === 'register' || + firstScreen === 'forgot_password') { + this.props.onLoadCompleted(); + this.setState({loading: false}); + this._showScreenAfterLogin(); + return; + } + // the extra q() ensures that synchronous exceptions hit the same codepath as // asynchronous ones. q().then(() => { @@ -840,14 +855,6 @@ module.exports = React.createClass({ _onLoadCompleted: function() { this.props.onLoadCompleted(); this.setState({loading: false}); - - // Show screens (like 'register') that need to be shown without _onLoggedIn - // being called. 'register' needs to be routed here when the email confirmation - // link is clicked on. - if (this.state.screenAfterLogin && - ['register'].indexOf(this.state.screenAfterLogin.screen) !== -1) { - this._showScreenAfterLogin(); - } }, /** @@ -946,6 +953,7 @@ module.exports = React.createClass({ this.state.screenAfterLogin.screen, this.state.screenAfterLogin.params, ); + // XXX: is this necessary? `showScreen` should do it for us. this.notifyNewScreen(this.state.screenAfterLogin.screen); this.setState({screenAfterLogin: null}); } else if (localStorage && localStorage.getItem('mx_last_room_id')) {