From 245e1986c1c5b61d2d30fff8ceebe1cf5132dd58 Mon Sep 17 00:00:00 2001
From: Geido <60598000+geido@users.noreply.github.com>
Date: Wed, 17 Jul 2024 15:10:37 +0300
Subject: [PATCH] chore: Clear redux localStorage on logout (#29602)
---
.../src/features/home/RightMenu.test.tsx | 27 +++++++++++++++++++
.../src/features/home/RightMenu.tsx | 6 ++++-
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/superset-frontend/src/features/home/RightMenu.test.tsx b/superset-frontend/src/features/home/RightMenu.test.tsx
index bb4a40a53..50c0ca325 100644
--- a/superset-frontend/src/features/home/RightMenu.test.tsx
+++ b/superset-frontend/src/features/home/RightMenu.test.tsx
@@ -346,3 +346,30 @@ test('If there is NOT a DB with allow_file_upload set as True the option should
(await screen.findByText('Upload CSV to database')).closest('a'),
).not.toBeInTheDocument();
});
+
+test('Logs out and clears local storage item redux', async () => {
+ const mockedProps = createProps();
+ resetUseSelectorMock();
+ render(, {
+ useRedux: true,
+ useQueryParams: true,
+ useRouter: true,
+ });
+
+ // Set an item in local storage to test if it gets cleared
+ localStorage.setItem('redux', JSON.stringify({ test: 'test' }));
+ expect(localStorage.getItem('redux')).not.toBeNull();
+
+ userEvent.hover(await screen.findByText(/Settings/i));
+
+ // Simulate user clicking the logout button
+ await waitFor(() => {
+ const logoutButton = screen.getByText('Logout');
+ userEvent.click(logoutButton);
+ });
+
+ // Wait for local storage to be cleared
+ await waitFor(() => {
+ expect(localStorage.getItem('redux')).toBeNull();
+ });
+});
diff --git a/superset-frontend/src/features/home/RightMenu.tsx b/superset-frontend/src/features/home/RightMenu.tsx
index 93e03f5ed..99a139836 100644
--- a/superset-frontend/src/features/home/RightMenu.tsx
+++ b/superset-frontend/src/features/home/RightMenu.tsx
@@ -348,6 +348,10 @@ const RightMenu = ({
const handleDatabaseAdd = () => setQuery({ databaseAdded: true });
+ const handleLogout = () => {
+ localStorage.removeItem('redux');
+ };
+
const theme = useTheme();
return (
@@ -512,7 +516,7 @@ const RightMenu = ({
{t('Info')}
)}
-
+
{t('Logout')}
,