From da49dd4409c9d8c02c43ef2727fa87570546408c Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 2 Aug 2019 11:22:42 +0100 Subject: [PATCH 1/2] Don't load guest sessions on post-registration login link If guest access was enabled, clicking the login link on the 'registration completed' page would just load the guest account you had before registering. Fixes https://github.com/vector-im/riot-web/issues/10482 --- src/Lifecycle.js | 12 ++++++++++-- src/components/structures/auth/Registration.js | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index fe7348e9c6..25914deefd 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -66,6 +66,9 @@ import TypingStore from "./stores/TypingStore"; * @params {string} opts.guestIsUrl: homeserver URL. Only used if enableGuest is * true; defines the IS to use. * + * @params {bool} opts.ignoreGuest: If the stored session is a guest account, ignore + * it and don't load it. + * * @returns {Promise} a promise which resolves when the above process completes. * Resolves to `true` if we ended up starting a session, or `false` if we * failed. @@ -96,7 +99,7 @@ export async function loadSession(opts) { guest: true, }, true).then(() => true); } - const success = await _restoreFromLocalStorage(); + const success = await _restoreFromLocalStorage(Boolean(opts.ignoreGuest)); if (success) { return true; } @@ -272,7 +275,7 @@ export function getLocalStorageSessionVars() { // The plan is to gradually move the localStorage access done here into // SessionStore to avoid bugs where the view becomes out-of-sync with // localStorage (e.g. isGuest etc.) -async function _restoreFromLocalStorage() { +async function _restoreFromLocalStorage(ignoreGuest) { if (!localStorage) { return false; } @@ -280,6 +283,11 @@ async function _restoreFromLocalStorage() { const {hsUrl, isUrl, accessToken, userId, deviceId, isGuest} = getLocalStorageSessionVars(); if (accessToken && userId && hsUrl) { + if (ignoreGuest && isGuest) { + console.log("Ignoring stored guest account: " + userId); + return false; + } + console.log(`Restoring session for ${userId}`); await _doSetLoggedIn({ userId: userId, diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index e825dd7034..fa390ace15 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -438,7 +438,7 @@ module.exports = React.createClass({ _onLoginClickWithCheck: async function(ev) { ev.preventDefault(); - const sessionLoaded = await Lifecycle.loadSession({}); + const sessionLoaded = await Lifecycle.loadSession({ignoreGuest: true}); if (!sessionLoaded) { // ok fine, there's still no session: really go to the login page this.props.onLoginClick(); From d4f0c38253b655e729727e2e07a0df1d386036a2 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 2 Aug 2019 16:44:49 +0100 Subject: [PATCH 2/2] Use options object --- src/Lifecycle.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 25914deefd..90911f813d 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -99,7 +99,9 @@ export async function loadSession(opts) { guest: true, }, true).then(() => true); } - const success = await _restoreFromLocalStorage(Boolean(opts.ignoreGuest)); + const success = await _restoreFromLocalStorage({ + ignoreGuest: Boolean(opts.ignoreGuest), + }); if (success) { return true; } @@ -275,7 +277,9 @@ export function getLocalStorageSessionVars() { // The plan is to gradually move the localStorage access done here into // SessionStore to avoid bugs where the view becomes out-of-sync with // localStorage (e.g. isGuest etc.) -async function _restoreFromLocalStorage(ignoreGuest) { +async function _restoreFromLocalStorage(opts) { + const ignoreGuest = opts.ignoreGuest; + if (!localStorage) { return false; }