🐛(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:
@@ -5,6 +5,7 @@ import { PropsWithChildren } from 'react';
|
|||||||
import { Box } from '@/components';
|
import { Box } from '@/components';
|
||||||
import { useConfig } from '@/core';
|
import { useConfig } from '@/core';
|
||||||
|
|
||||||
|
import { HOME_URL } from '../conf';
|
||||||
import { useAuth } from '../hooks';
|
import { useAuth } from '../hooks';
|
||||||
import { getAuthUrl, gotoLogin } from '../utils';
|
import { getAuthUrl, gotoLogin } from '../utils';
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ export const Auth = ({ children }: PropsWithChildren) => {
|
|||||||
*/
|
*/
|
||||||
if (!authenticated && !pathAllowed) {
|
if (!authenticated && !pathAllowed) {
|
||||||
if (config?.FRONTEND_HOMEPAGE_FEATURE_ENABLED) {
|
if (config?.FRONTEND_HOMEPAGE_FEATURE_ENABLED) {
|
||||||
void replace('/home');
|
void replace(HOME_URL);
|
||||||
} else {
|
} else {
|
||||||
gotoLogin();
|
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 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('/');
|
void replace('/');
|
||||||
return (
|
return (
|
||||||
<Box $height="100vh" $width="100vw" $align="center" $justify="center">
|
<Box $height="100vh" $width="100vw" $align="center" $justify="center">
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { baseApiUrl } from '@/api';
|
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 LOGIN_URL = `${baseApiUrl()}authenticate/`;
|
||||||
export const LOGOUT_URL = `${baseApiUrl()}logout/`;
|
export const LOGOUT_URL = `${baseApiUrl()}logout/`;
|
||||||
|
export const PATH_AUTH_LOCAL_STORAGE = 'docs-path-auth';
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export * from './api';
|
export * from './api';
|
||||||
export * from './components';
|
export * from './components';
|
||||||
|
export * from './conf';
|
||||||
export * from './hooks';
|
export * from './hooks';
|
||||||
export * from './utils';
|
export * from './utils';
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { HomeContent } from '@/features/home';
|
import { useRouter } from 'next/router';
|
||||||
import { NextPageWithLayout } from '@/types/next';
|
|
||||||
|
|
||||||
const Page: NextPageWithLayout = () => {
|
import { HOME_URL } from '@/features/auth';
|
||||||
return <HomeContent />;
|
|
||||||
|
const Page = () => {
|
||||||
|
const { replace } = useRouter();
|
||||||
|
void replace(HOME_URL);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Page;
|
export default Page;
|
||||||
|
|||||||
Reference in New Issue
Block a user