🐛(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.
This commit is contained in:
Anthony LC
2025-05-15 10:51:05 +02:00
parent fc1d33268c
commit 62d1bc6473
4 changed files with 12 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ import { PropsWithChildren } from 'react';
import { Box } from '@/components';
import { useConfig } from '@/core';
import { HOME_URL } from '../conf';
import { useAuth } from '../hooks';
import { getAuthUrl, gotoLogin } from '../utils';
@@ -43,7 +44,7 @@ export const Auth = ({ children }: PropsWithChildren) => {
*/
if (!authenticated && !pathAllowed) {
if (config?.FRONTEND_HOMEPAGE_FEATURE_ENABLED) {
void replace('/home');
void replace(HOME_URL);
} else {
gotoLogin();
}
@@ -57,7 +58,7 @@ export const Auth = ({ children }: PropsWithChildren) => {
/**
* If the user is authenticated and the path is the home page, we redirect to the index.
*/
if (pathname === '/home' && authenticated) {
if (pathname === HOME_URL && authenticated) {
void replace('/');
return (
<Box $height="100vh" $width="100vw" $align="center" $justify="center">

View File

@@ -1,5 +1,6 @@
import { baseApiUrl } from '@/api';
export const PATH_AUTH_LOCAL_STORAGE = 'docs-path-auth';
export const HOME_URL = '/home';
export const LOGIN_URL = `${baseApiUrl()}authenticate/`;
export const LOGOUT_URL = `${baseApiUrl()}logout/`;
export const PATH_AUTH_LOCAL_STORAGE = 'docs-path-auth';

View File

@@ -1,4 +1,5 @@
export * from './api';
export * from './components';
export * from './conf';
export * from './hooks';
export * from './utils';

View File

@@ -1,8 +1,10 @@
import { HomeContent } from '@/features/home';
import { NextPageWithLayout } from '@/types/next';
import { useRouter } from 'next/router';
const Page: NextPageWithLayout = () => {
return <HomeContent />;
import { HOME_URL } from '@/features/auth';
const Page = () => {
const { replace } = useRouter();
void replace(HOME_URL);
};
export default Page;