mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
Use forced segment inside logout
This commit is contained in:
parent
0f2b7a1ce9
commit
5521862498
@ -40,28 +40,28 @@ export class RootViewModel extends ViewModel {
|
||||
this.track(this.navigation.observe("login").subscribe(() => this._applyNavigation()));
|
||||
this.track(this.navigation.observe("session").subscribe(() => this._applyNavigation()));
|
||||
this.track(this.navigation.observe("sso").subscribe(() => this._applyNavigation()));
|
||||
this.track(this.navigation.observe("forced-logout").subscribe(() => this._applyNavigation()));
|
||||
this.track(this.navigation.observe("logout").subscribe(() => this._applyNavigation()));
|
||||
this._applyNavigation(true);
|
||||
}
|
||||
|
||||
async _applyNavigation(shouldRestoreLastUrl) {
|
||||
const isLogin = this.navigation.path.get("login");
|
||||
const logoutSessionId = this.navigation.path.get("logout")?.value;
|
||||
const forcedLogoutSessionId = this.navigation.path.get("forced-logout")?.value;
|
||||
const isForcedLogout = this.navigation.path.get("forced")?.value;
|
||||
const sessionId = this.navigation.path.get("session")?.value;
|
||||
const loginToken = this.navigation.path.get("sso")?.value;
|
||||
if (isLogin) {
|
||||
if (this.activeSection !== "login") {
|
||||
this._showLogin();
|
||||
}
|
||||
} else if (logoutSessionId && isForcedLogout) {
|
||||
if (this.activeSection !== "forced-logout") {
|
||||
this._showForcedLogout(logoutSessionId);
|
||||
}
|
||||
} else if (logoutSessionId) {
|
||||
if (this.activeSection !== "logout") {
|
||||
this._showLogout(logoutSessionId);
|
||||
}
|
||||
} else if (forcedLogoutSessionId) {
|
||||
if (this.activeSection !== "forced-logout") {
|
||||
this._showForcedLogout(forcedLogoutSessionId);
|
||||
}
|
||||
} else if (sessionId === true) {
|
||||
if (this.activeSection !== "picker") {
|
||||
this._showPicker();
|
||||
|
@ -23,7 +23,7 @@ export type SegmentType = {
|
||||
"session": string | boolean;
|
||||
"sso": string;
|
||||
"logout": true;
|
||||
"forced-logout": true;
|
||||
"forced": true;
|
||||
"room": string;
|
||||
"rooms": string[];
|
||||
"settings": true;
|
||||
@ -49,9 +49,7 @@ function allowsChild(parent: Segment<SegmentType> | undefined, child: Segment<Se
|
||||
switch (parent?.type) {
|
||||
case undefined:
|
||||
// allowed root segments
|
||||
return type === "login" || type === "session"
|
||||
|| type === "sso" || type === "logout"
|
||||
|| type === "forced-logout";
|
||||
return type === "login" || type === "session" || type === "sso" || type === "logout";
|
||||
case "session":
|
||||
return type === "room" || type === "rooms" || type === "settings" || type === "create-room";
|
||||
case "rooms":
|
||||
@ -61,6 +59,8 @@ function allowsChild(parent: Segment<SegmentType> | undefined, child: Segment<Se
|
||||
return type === "lightbox" || type === "right-panel";
|
||||
case "right-panel":
|
||||
return type === "details"|| type === "members" || type === "member";
|
||||
case "logout":
|
||||
return type === "forced";
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -101,7 +101,12 @@ export class SessionViewModel extends ViewModel {
|
||||
const error = this._client.sync.error;
|
||||
if (error.errcode === "M_UNKNOWN_TOKEN") {
|
||||
// Access token is no longer valid, so force the user to log out
|
||||
this.navigation.push("forced-logout", this.id);
|
||||
const segments = [
|
||||
this.navigation.segment("logout", this.id),
|
||||
this.navigation.segment("forced", true),
|
||||
];
|
||||
const path = this.navigation.pathFrom(segments);
|
||||
this.navigation.applyPath(path);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user