Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Log out of the guest account if coming from the welcome page
Browse files Browse the repository at this point in the history
This is ultimately the fix for element-hq/element-web#9224 however it is not really great. By not logging out of the guest account, getCurrentHsUrl() returns the wrong homeserver URL (matrix.org) instead of the discovered one.
  • Loading branch information
turt2live committed Mar 23, 2019
1 parent 68997f9 commit 5b2328b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
16 changes: 9 additions & 7 deletions src/Lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions src/components/structures/MatrixChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5b2328b

Please sign in to comment.