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

Manage guest accounts better on the welcome page for auth #2819

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/Lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ let _isLoggingOut = false;

/**
* Logs the current session out and transitions to the logged-out state
* @returns {Promise} a promise which resolves when the logout has finished.
*/
export function logout() {
if (!MatrixClientPeg.get()) return;
Expand All @@ -415,16 +416,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) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think it's more typical to not include reject at all if it's unused, at least for code I've seen here so far...

// 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
31 changes: 24 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 Expand Up @@ -1828,6 +1839,12 @@ export default React.createClass({
defaultIsUrl: isUrl,
loadingDefaultHomeserver: false,
});

// Change over the guest account, if one exists
if (MatrixClientPeg.get() && MatrixClientPeg.get().isGuest()) {
console.log("Discovered homeserver URLs - logging out current guest to use the homeserver");
Lifecycle.logout().then(() => this._loadSession());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, so this will remake a new guest account once we discover the HS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, although it could probably do with a comment (or even better: not doing this and actually implementing the plan we talked about)

}
}
} catch (e) {
console.error(e);
Expand Down