Merge pull request #3273 from matrix-org/dbkr/dont_load_guest_session

Don't load guest sessions on post-registration login link
This commit is contained in:
David Baker 2019-08-02 17:46:00 +01:00 committed by GitHub
commit 5f45bbd6b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -66,6 +66,9 @@ import TypingStore from "./stores/TypingStore";
* @params {string} opts.guestIsUrl: homeserver URL. Only used if enableGuest is * @params {string} opts.guestIsUrl: homeserver URL. Only used if enableGuest is
* true; defines the IS to use. * 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. * @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 * Resolves to `true` if we ended up starting a session, or `false` if we
* failed. * failed.
@ -96,7 +99,9 @@ export async function loadSession(opts) {
guest: true, guest: true,
}, true).then(() => true); }, true).then(() => true);
} }
const success = await _restoreFromLocalStorage(); const success = await _restoreFromLocalStorage({
ignoreGuest: Boolean(opts.ignoreGuest),
});
if (success) { if (success) {
return true; return true;
} }
@ -272,7 +277,9 @@ export function getLocalStorageSessionVars() {
// The plan is to gradually move the localStorage access done here into // The plan is to gradually move the localStorage access done here into
// SessionStore to avoid bugs where the view becomes out-of-sync with // SessionStore to avoid bugs where the view becomes out-of-sync with
// localStorage (e.g. isGuest etc.) // localStorage (e.g. isGuest etc.)
async function _restoreFromLocalStorage() { async function _restoreFromLocalStorage(opts) {
const ignoreGuest = opts.ignoreGuest;
if (!localStorage) { if (!localStorage) {
return false; return false;
} }
@ -280,6 +287,11 @@ async function _restoreFromLocalStorage() {
const {hsUrl, isUrl, accessToken, userId, deviceId, isGuest} = getLocalStorageSessionVars(); const {hsUrl, isUrl, accessToken, userId, deviceId, isGuest} = getLocalStorageSessionVars();
if (accessToken && userId && hsUrl) { if (accessToken && userId && hsUrl) {
if (ignoreGuest && isGuest) {
console.log("Ignoring stored guest account: " + userId);
return false;
}
console.log(`Restoring session for ${userId}`); console.log(`Restoring session for ${userId}`);
await _doSetLoggedIn({ await _doSetLoggedIn({
userId: userId, userId: userId,

View file

@ -438,7 +438,7 @@ module.exports = React.createClass({
_onLoginClickWithCheck: async function(ev) { _onLoginClickWithCheck: async function(ev) {
ev.preventDefault(); ev.preventDefault();
const sessionLoaded = await Lifecycle.loadSession({}); const sessionLoaded = await Lifecycle.loadSession({ignoreGuest: true});
if (!sessionLoaded) { if (!sessionLoaded) {
// ok fine, there's still no session: really go to the login page // ok fine, there's still no session: really go to the login page
this.props.onLoginClick(); this.props.onLoginClick();