From 1beca653b772cf10586c417b2c25df03a67df8a2 Mon Sep 17 00:00:00 2001
From: TheArcaneBrony
Date: Mon, 17 Jul 2023 00:21:24 +0200
Subject: Handle external logouts
---
MatrixRoomUtils.Web/Pages/About.razor | 4 +-
MatrixRoomUtils.Web/Pages/Index.razor | 18 ++++-
MatrixRoomUtils.Web/Pages/InvalidSession.razor | 97 ++++++++++++++++++++++++
MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor | 10 ++-
4 files changed, 119 insertions(+), 10 deletions(-)
create mode 100644 MatrixRoomUtils.Web/Pages/InvalidSession.razor
(limited to 'MatrixRoomUtils.Web/Pages')
diff --git a/MatrixRoomUtils.Web/Pages/About.razor b/MatrixRoomUtils.Web/Pages/About.razor
index b8d9c4a..971bd9b 100644
--- a/MatrixRoomUtils.Web/Pages/About.razor
+++ b/MatrixRoomUtils.Web/Pages/About.razor
@@ -1,4 +1,4 @@
-@page "/About"
+@page "/About"
@using System.Net
@using System.Net.Sockets
@inject NavigationManager NavigationManager
@@ -56,7 +56,7 @@
var message = "Hello, World!\nThis is a terminal emulator!\n\nYou can type stuff here, and it will be sent to the server!\n\nThis is a test of the emergency broadcast system.\n\nThis is only a t";
_terminal.Options.RendererType = RendererType.Dom;
_terminal.Options.ScreenReaderMode = true;
- TcpClient.
+// TcpClient.
for (var i = 0; i < message.Length; i++) {
await _terminal.Write(message[i].ToString());
diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor
index 16a6cee..01e2be4 100644
--- a/MatrixRoomUtils.Web/Pages/Index.razor
+++ b/MatrixRoomUtils.Web/Pages/Index.razor
@@ -21,10 +21,10 @@ Small collection of tools to do not-so-everyday things.
SwitchSession(_auth))" style="text-decoration-line: unset;"/>
@_user.DisplayName on @_auth.Homeserver RemoveUser(_auth))">Remove
-
+
Member of @_user.RoomCount rooms
-
+
}
@@ -39,7 +39,17 @@ Small collection of tools to do not-so-everyday things.
var tokens = await MRUStorage.GetAllTokens();
var profileTasks = tokens.Select(async token => {
UserInfo userInfo = new();
- var hs = await HomeserverProvider.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken);
+ AuthenticatedHomeServer hs;
+ try {
+ hs = await HomeserverProvider.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken);
+ }
+ catch (MatrixException e) {
+ if (e.ErrorCode == "M_UNKNOWN_TOKEN") {
+ NavigationManager.NavigateTo("/InvalidSession?ctx="+token.AccessToken);
+ return;
+ }
+ throw;
+ }
var roomCountTask = hs.GetJoinedRooms();
var profile = await hs.GetProfile(hs.WhoAmI.UserId);
userInfo.DisplayName = profile.DisplayName ?? hs.WhoAmI.UserId;
@@ -75,4 +85,4 @@ Small collection of tools to do not-so-everyday things.
await MRUStorage.SetCurrentToken(auth);
await OnInitializedAsync();
}
-}
\ No newline at end of file
+}
diff --git a/MatrixRoomUtils.Web/Pages/InvalidSession.razor b/MatrixRoomUtils.Web/Pages/InvalidSession.razor
new file mode 100644
index 0000000..3bcd797
--- /dev/null
+++ b/MatrixRoomUtils.Web/Pages/InvalidSession.razor
@@ -0,0 +1,97 @@
+@page "/InvalidSession"
+@using MatrixRoomUtils.Core.Helpers
+@using MatrixRoomUtils.Core.Responses
+@using MatrixRoomUtils.Web.Shared.SimpleComponents
+
+Invalid session
+
+
Rory&::MatrixUtils - Invalid session encountered
+
A session was encountered that is no longer valid. This can happen if you have logged out of the account on another device, or if the access token has expired.
+
+@if (_login is not null) {
+
It appears that the affected user is @_login.UserId (@_login.DeviceId) on @_login.Homeserver!
+ Refresh token
+ Remove
+
+ @if (_showRefreshDialog) {
+
+
+ Log in
+ @if (_loginException is not null) {
+