Skip to content

Commit

Permalink
feat(ui): remember previous location when token refresh logs you out (a…
Browse files Browse the repository at this point in the history
…kuity#1986)

Signed-off-by: Remington Breeze <remington@breeze.software>
  • Loading branch information
rbreeze authored May 9, 2024
1 parent bef5760 commit ac34d6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ui/src/config/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { paths } from './paths';

const logout = () => {
localStorage.removeItem(authTokenKey);
window.location.replace(paths.login);
window.location.replace(`${paths.login}?${redirectToQueryParam}=${window.location.pathname}`);
};

const renewToken = () => {
Expand Down
7 changes: 5 additions & 2 deletions ui/src/pages/login/login.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useQuery } from '@connectrpc/connect-query';
import { Divider, Typography } from 'antd';
import { Navigate } from 'react-router-dom';
import { Navigate, generatePath, useSearchParams } from 'react-router-dom';

import { redirectToQueryParam } from '@ui/config/auth';
import { paths } from '@ui/config/paths';
import { AdminLogin } from '@ui/features/auth/admin-login';
import { useAuthContext } from '@ui/features/auth/context/use-auth-context';
Expand All @@ -13,10 +14,12 @@ import * as styles from './login.module.less';

export const Login = () => {
const { data, isLoading } = useQuery(getPublicConfig);
const [params] = useSearchParams();
const { isLoggedIn } = useAuthContext();
const redirectTo = params.get(redirectToQueryParam);

if (isLoggedIn) {
return <Navigate to={paths.home} replace />;
return <Navigate to={redirectTo ? generatePath(redirectTo) : paths.home} replace />;
}

return (
Expand Down

0 comments on commit ac34d6e

Please sign in to comment.