From b925c631712789bf54f8c10b170040541eeb5ebd Mon Sep 17 00:00:00 2001 From: Aine Date: Thu, 7 Nov 2024 10:46:25 +0200 Subject: [PATCH] clear storage on logout --- src/components/AdminLayout.tsx | 4 ++-- src/components/config.ts | 17 +++++++++++++++++ src/synapse/authProvider.ts | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/AdminLayout.tsx b/src/components/AdminLayout.tsx index 832e758..15a3310 100644 --- a/src/components/AdminLayout.tsx +++ b/src/components/AdminLayout.tsx @@ -2,6 +2,7 @@ import { AppBar, TitlePortal, InspectorButton, Confirm, Layout, Logout, Menu, us import { LoginMethod } from "../pages/LoginPage"; import { useEffect, useState, Suspense } from "react"; import { Icons, DefaultIcon } from "./icons"; +import { ClearConfig } from "./config"; const AdminUserMenu = () => { const [open, setOpen] = useState(false); @@ -21,8 +22,7 @@ const AdminUserMenu = () => { const handleDialogClose = () => { setOpen(false); - localStorage.removeItem("access_token"); - localStorage.removeItem("login_type"); + ClearConfig(); window.location.reload(); }; diff --git a/src/components/config.ts b/src/components/config.ts index 96c3171..be88392 100644 --- a/src/components/config.ts +++ b/src/components/config.ts @@ -68,3 +68,20 @@ export const LoadConfig = (context: Config): Config => { } as Config; } + + +export const ClearConfig = () => { + // config.json + storage.removeItem("restrict_base_url"); + storage.removeItem("as_managed_users"); + storage.removeItem("support_url"); + storage.removeItem("menu"); + + // session + storage.removeItem("home_server"); + storage.removeItem("base_url"); + storage.removeItem("user_id"); + storage.removeItem("device_id"); + storage.removeItem("access_token"); + storage.removeItem("login_type"); +} diff --git a/src/synapse/authProvider.ts b/src/synapse/authProvider.ts index 3de09a6..e9e12f6 100644 --- a/src/synapse/authProvider.ts +++ b/src/synapse/authProvider.ts @@ -3,6 +3,7 @@ import { AuthProvider, HttpError, Options, fetchUtils } from "react-admin"; import storage from "../storage"; import { MatrixError, displayError } from "../components/error"; import { fetchAuthenticatedMedia } from "../utils/fetchMedia"; +import { ClearConfig } from "../components/config"; const authProvider: AuthProvider = { // called when the user attempts to log in @@ -154,8 +155,7 @@ const authProvider: AuthProvider = { } catch (err) { console.log("Error logging out", err); } finally { - storage.removeItem("access_token"); - storage.removeItem("login_type"); + ClearConfig(); } } },