From 5c14929f7b21221cc036e3819103f82021a379e1 Mon Sep 17 00:00:00 2001 From: Fredrik Strand Oseberg Date: Tue, 1 Feb 2022 14:47:14 +0100 Subject: [PATCH] Fix/login redirect set password (#652) * fix: don't redirect when path is reset-password or new-user * fix: add comments to relevant routes * fix: update swr provider --- frontend/src/component/menu/routes.js | 4 ++++ .../component/providers/SWRProvider/SWRProvider.tsx | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend/src/component/menu/routes.js b/frontend/src/component/menu/routes.js index fae9398d48..8359ee178a 100644 --- a/frontend/src/component/menu/routes.js +++ b/frontend/src/component/menu/routes.js @@ -490,6 +490,8 @@ export const routes = [ layout: 'main', menu: {}, }, + /* If you update this route path, make sure you update the path in SWRProvider.tsx */ + { path: '/login', title: 'Log in', @@ -499,6 +501,7 @@ export const routes = [ layout: 'standalone', menu: {}, }, + /* If you update this route path, make sure you update the path in SWRProvider.tsx */ { path: '/new-user', title: 'New user', @@ -508,6 +511,7 @@ export const routes = [ layout: 'standalone', menu: {}, }, + /* If you update this route path, make sure you update the path in SWRProvider.tsx */ { path: '/reset-password', title: 'reset-password', diff --git a/frontend/src/component/providers/SWRProvider/SWRProvider.tsx b/frontend/src/component/providers/SWRProvider/SWRProvider.tsx index 0a082cf9ad..048498eaa6 100644 --- a/frontend/src/component/providers/SWRProvider/SWRProvider.tsx +++ b/frontend/src/component/providers/SWRProvider/SWRProvider.tsx @@ -22,17 +22,23 @@ const SWRProvider: React.FC = ({ const handleFetchError = error => { setShowLoader(false); if (error.status === 401) { - cache.clear(); const path = location.pathname; // Only populate user with authDetails if 401 and // error is not invalid token if (error?.info?.name !== INVALID_TOKEN_ERROR) { mutate(USER_CACHE_KEY, { ...error.info }, false); } - if (path === '/login') { + + if ( + path === '/login' || + path === '/new-user' || + path === '/reset-password' + ) { return; } + cache.clear(); + history.push('/login'); return; }