Skip to content

Commit

Permalink
fix: add session storage stored login-redirect as override for initia…
Browse files Browse the repository at this point in the history
…l redirect

Signed-off-by: andreas-unleash <[email protected]>
  • Loading branch information
andreas-unleash committed Jan 19, 2024
1 parent 13eec0b commit 94e56b4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 4 additions & 1 deletion frontend/src/component/InitialRedirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { useNavigate } from 'react-router-dom';
import useProjects from '../hooks/api/getters/useProjects/useProjects';
import { useLastViewedProject } from '../hooks/useLastViewedProject';
import Loader from './common/Loader/Loader';
import { getSessionStorageItem, setSessionStorageItem } from "../utils/storage";

export const InitialRedirect = () => {
const { lastViewed } = useLastViewedProject();
const { projects, loading } = useProjects();
const navigate = useNavigate();
const sessionRedirect = getSessionStorageItem('login-redirect');

// Redirect based on project and last viewed
const getRedirect = useCallback(() => {
Expand All @@ -23,10 +25,11 @@ export const InitialRedirect = () => {
}, [lastViewed, projects]);

const redirect = () => {
navigate(getRedirect(), { replace: true });
navigate(sessionRedirect ?? getRedirect(), { replace: true });
};

useEffect(() => {
setSessionStorageItem('login-redirect');
redirect();
}, [getRedirect]);

Expand Down
1 change: 0 additions & 1 deletion frontend/src/component/user/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const Login = () => {
query.get('redirect') || getSessionStorageItem('login-redirect') || '/';

if (user) {
setSessionStorageItem('login-redirect');
return <Navigate to={parseRedirectParam(redirect)} replace />;
}

Expand Down

0 comments on commit 94e56b4

Please sign in to comment.