Skip to content

Commit a369782

Browse files
committed
🐛(frontend) redirect to /home
The page '/login' was replaced with '/home', but some users may still have the old URL in their bookmarks, it can create a loop during the authentication process. We redirect the user to '/home' if they try to access '/login' page, it will prevent edge cases.
1 parent 9ecec3b commit a369782

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

src/frontend/apps/impress/src/features/auth/components/Auth.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { PropsWithChildren } from 'react';
55
import { Box } from '@/components';
66
import { useConfig } from '@/core';
77

8+
import { HOME_URL } from '../conf';
89
import { useAuth } from '../hooks';
910
import { getAuthUrl, gotoLogin } from '../utils';
1011

@@ -43,7 +44,7 @@ export const Auth = ({ children }: PropsWithChildren) => {
4344
*/
4445
if (!authenticated && !pathAllowed) {
4546
if (config?.FRONTEND_HOMEPAGE_FEATURE_ENABLED) {
46-
void replace('/home');
47+
void replace(HOME_URL);
4748
} else {
4849
gotoLogin();
4950
}
@@ -57,7 +58,7 @@ export const Auth = ({ children }: PropsWithChildren) => {
5758
/**
5859
* If the user is authenticated and the path is the home page, we redirect to the index.
5960
*/
60-
if (pathname === '/home' && authenticated) {
61+
if (pathname === HOME_URL && authenticated) {
6162
void replace('/');
6263
return (
6364
<Box $height="100vh" $width="100vw" $align="center" $justify="center">
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { baseApiUrl } from '@/api';
22

3-
export const PATH_AUTH_LOCAL_STORAGE = 'docs-path-auth';
3+
export const HOME_URL = '/home';
44
export const LOGIN_URL = `${baseApiUrl()}authenticate/`;
55
export const LOGOUT_URL = `${baseApiUrl()}logout/`;
6+
export const PATH_AUTH_LOCAL_STORAGE = 'docs-path-auth';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './api';
22
export * from './components';
3+
export * from './conf';
34
export * from './hooks';
45
export * from './utils';
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { HomeContent } from '@/features/home';
2-
import { NextPageWithLayout } from '@/types/next';
1+
import { useRouter } from 'next/router';
32

4-
const Page: NextPageWithLayout = () => {
5-
return <HomeContent />;
3+
import { HOME_URL } from '@/features/auth';
4+
5+
const Page = () => {
6+
const { replace } = useRouter();
7+
void replace(HOME_URL);
68
};
79

810
export default Page;

0 commit comments

Comments
 (0)