diff --git a/src/domain/session/SessionViewModel.js b/src/domain/session/SessionViewModel.js index a67df3a7..3bbcc08a 100644 --- a/src/domain/session/SessionViewModel.js +++ b/src/domain/session/SessionViewModel.js @@ -28,6 +28,7 @@ import {CreateRoomViewModel} from "./CreateRoomViewModel.js"; import {ViewModel} from "../ViewModel"; import {RoomViewModelObservable} from "./RoomViewModelObservable.js"; import {RightPanelViewModel} from "./rightpanel/RightPanelViewModel.js"; +import {SyncStatus} from "../../matrix/Sync.js"; export class SessionViewModel extends ViewModel { constructor(options) { @@ -45,6 +46,7 @@ export class SessionViewModel extends ViewModel { this._gridViewModel = null; this._createRoomViewModel = null; this._setupNavigation(); + this._setupForcedLogoutOnAccessTokenInvalidation(); } _setupNavigation() { @@ -93,6 +95,18 @@ export class SessionViewModel extends ViewModel { this._updateRightPanel(); } + _setupForcedLogoutOnAccessTokenInvalidation() { + this._client.sync.status.subscribe(status => { + if (status === SyncStatus.Stopped) { + 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); + } + } + }); + } + get id() { return this._client.sessionId; }