Use forced segment inside logout

This commit is contained in:
RMidhunSuresh 2022-08-24 16:03:00 +05:30
parent 0f2b7a1ce9
commit 5521862498
3 changed files with 16 additions and 11 deletions

View File

@ -40,28 +40,28 @@ export class RootViewModel extends ViewModel {
this.track(this.navigation.observe("login").subscribe(() => this._applyNavigation())); this.track(this.navigation.observe("login").subscribe(() => this._applyNavigation()));
this.track(this.navigation.observe("session").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("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); this._applyNavigation(true);
} }
async _applyNavigation(shouldRestoreLastUrl) { async _applyNavigation(shouldRestoreLastUrl) {
const isLogin = this.navigation.path.get("login"); const isLogin = this.navigation.path.get("login");
const logoutSessionId = this.navigation.path.get("logout")?.value; 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 sessionId = this.navigation.path.get("session")?.value;
const loginToken = this.navigation.path.get("sso")?.value; const loginToken = this.navigation.path.get("sso")?.value;
if (isLogin) { if (isLogin) {
if (this.activeSection !== "login") { if (this.activeSection !== "login") {
this._showLogin(); this._showLogin();
} }
} else if (logoutSessionId && isForcedLogout) {
if (this.activeSection !== "forced-logout") {
this._showForcedLogout(logoutSessionId);
}
} else if (logoutSessionId) { } else if (logoutSessionId) {
if (this.activeSection !== "logout") { if (this.activeSection !== "logout") {
this._showLogout(logoutSessionId); this._showLogout(logoutSessionId);
} }
} else if (forcedLogoutSessionId) {
if (this.activeSection !== "forced-logout") {
this._showForcedLogout(forcedLogoutSessionId);
}
} else if (sessionId === true) { } else if (sessionId === true) {
if (this.activeSection !== "picker") { if (this.activeSection !== "picker") {
this._showPicker(); this._showPicker();

View File

@ -23,7 +23,7 @@ export type SegmentType = {
"session": string | boolean; "session": string | boolean;
"sso": string; "sso": string;
"logout": true; "logout": true;
"forced-logout": true; "forced": true;
"room": string; "room": string;
"rooms": string[]; "rooms": string[];
"settings": true; "settings": true;
@ -49,9 +49,7 @@ function allowsChild(parent: Segment<SegmentType> | undefined, child: Segment<Se
switch (parent?.type) { switch (parent?.type) {
case undefined: case undefined:
// allowed root segments // allowed root segments
return type === "login" || type === "session" return type === "login" || type === "session" || type === "sso" || type === "logout";
|| type === "sso" || type === "logout"
|| type === "forced-logout";
case "session": case "session":
return type === "room" || type === "rooms" || type === "settings" || type === "create-room"; return type === "room" || type === "rooms" || type === "settings" || type === "create-room";
case "rooms": case "rooms":
@ -61,6 +59,8 @@ function allowsChild(parent: Segment<SegmentType> | undefined, child: Segment<Se
return type === "lightbox" || type === "right-panel"; return type === "lightbox" || type === "right-panel";
case "right-panel": case "right-panel":
return type === "details"|| type === "members" || type === "member"; return type === "details"|| type === "members" || type === "member";
case "logout":
return type === "forced";
default: default:
return false; return false;
} }

View File

@ -101,7 +101,12 @@ export class SessionViewModel extends ViewModel {
const error = this._client.sync.error; const error = this._client.sync.error;
if (error.errcode === "M_UNKNOWN_TOKEN") { if (error.errcode === "M_UNKNOWN_TOKEN") {
// Access token is no longer valid, so force the user to log out // 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);
} }
} }
}); });