Skip to content

Commit c1f21a0

Browse files
chore(deps): update dependency react-router to v7.5.2 [security] (#1974)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: DustyD <xiao_peng0202@hotmail.com>
1 parent 354ed27 commit c1f21a0

File tree

4 files changed

+59
-83
lines changed

4 files changed

+59
-83
lines changed

frontend/package-lock.json

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"react-beforeunload": "^2.6.0",
4141
"react-dom": "^18.2.0",
4242
"react-hash-string": "^1.0.0",
43-
"react-router": "^7.1.1",
43+
"react-router": "^7.5.2",
4444
"react-test-renderer": "^18.2.0",
4545
"react-toastify": "^11.0.0",
4646
"sass": "^1.77.7",

frontend/src/App.tsx

Lines changed: 12 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { useContext, useEffect, useMemo } from 'react';
1+
import React, { useContext, useEffect } from 'react';
22
import {
3-
createBrowserRouter, RouteObject, RouterProvider
3+
BrowserRouter
44
} from 'react-router';
55
import { Amplify } from 'aws-amplify';
66
import { ClassPrefix } from '@carbon/react';
@@ -11,19 +11,11 @@ import awsconfig from './aws-exports';
1111
import prefix from './styles/classPrefix';
1212
import './styles/custom.scss';
1313
import 'react-toastify/dist/ReactToastify.css';
14-
15-
import Layout from './layout/PrivateLayout';
16-
import Landing from './views/Landing';
17-
import FourOhFour from './views/ErrorViews/FourOhFour';
18-
import LoginOrgSelection from './views/LoginOrgSelection';
19-
import ServiceStatus from './views/ServiceStatus';
2014
import { NavigateProvider } from './contexts/NavigationContext';
2115
import AuthContext from './contexts/AuthContext';
22-
import BrowserRoutes from './routes';
23-
import ROUTES from './routes/constants';
24-
import ProtectedRoute from './routes/ProtectedRoute';
2516
import { ThemePreference } from './utils/ThemePreference';
2617
import CustomQueryProvider from './components/CustomQueryProvider';
18+
import AppRoutes from './AppRoutes';
2719

2820
Amplify.configure(awsconfig);
2921

@@ -33,82 +25,25 @@ Amplify.configure(awsconfig);
3325
* @returns {JSX.Element} instance of the app ready to use.
3426
*/
3527
const App: React.FC = () => {
36-
const { signed, isCurrentAuthUser, selectedClientRoles } = useContext(AuthContext);
28+
const { isCurrentAuthUser } = useContext(AuthContext);
3729

3830
useEffect(() => {
3931
isCurrentAuthUser(window.location.pathname);
4032
}, []);
4133

42-
const roleSelectionRoutes: RouteObject[] = [
43-
{
44-
path: ROUTES.ALL_ROUTES,
45-
element: <LoginOrgSelection />
46-
}
47-
];
48-
49-
const signedRoutes: RouteObject[] = [
50-
{
51-
path: ROUTES.ROOT,
52-
element: <ProtectedRoute />,
53-
children: [
54-
{
55-
element: <Layout />,
56-
children: BrowserRoutes
57-
}
58-
]
59-
},
60-
{
61-
path: ROUTES.FOUR_OH_FOUR,
62-
element: <FourOhFour />
63-
},
64-
{
65-
path: ROUTES.ALL_ROUTES,
66-
element: <FourOhFour />
67-
}
68-
];
69-
70-
const notSignedRoutes: RouteObject[] = [
71-
{
72-
path: ROUTES.ALL_ROUTES,
73-
element: <Landing />
74-
}
75-
];
76-
77-
const sharedRoutes: RouteObject[] = [
78-
{
79-
path: ROUTES.SERVICE_STATUS,
80-
element: <ServiceStatus />
81-
}
82-
];
83-
84-
const browserRouter = useMemo(() => {
85-
const selectBrowserRoutes = () => {
86-
if (!signed) {
87-
return notSignedRoutes;
88-
}
89-
if (selectedClientRoles) {
90-
return signedRoutes;
91-
}
92-
return roleSelectionRoutes;
93-
};
94-
95-
const selectedRoutes = selectBrowserRoutes();
96-
selectedRoutes.push(...sharedRoutes);
97-
98-
return createBrowserRouter(selectedRoutes);
99-
}, [signed, selectedClientRoles]);
100-
101-
const handleRedirectTo403 = () => {
102-
browserRouter.navigate('/403');
103-
};
104-
10534
return (
10635
<ClassPrefix prefix={prefix}>
10736
<ThemePreference>
108-
<NavigateProvider onRedirect={handleRedirectTo403}>
37+
<NavigateProvider onRedirect={() => {
38+
// go to 403 page
39+
window.location.href = '/403';
40+
}}
41+
>
10942
<CustomQueryProvider>
11043
<ToastContainer />
111-
<RouterProvider router={browserRouter} />
44+
<BrowserRouter>
45+
<AppRoutes />
46+
</BrowserRouter>
11247
<ReactQueryDevtools initialIsOpen={false} />
11348
</CustomQueryProvider>
11449
</NavigateProvider>

frontend/src/AppRoutes.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable no-nested-ternary */
2+
import React, { useContext } from 'react';
3+
import { useRoutes, Navigate, Outlet } from 'react-router';
4+
import AuthContext from './contexts/AuthContext';
5+
import ROUTES from './routes/constants';
6+
import Landing from './views/Landing';
7+
import LoginOrgSelection from './views/LoginOrgSelection';
8+
import Layout from './layout/PrivateLayout';
9+
import ServiceStatus from './views/ServiceStatus';
10+
import FourOhFour from './views/ErrorViews/FourOhFour';
11+
import BrowserRoutes from './routes';
12+
13+
const AppRoutes = () => {
14+
const { signed, signOut, selectedClientRoles } = useContext(AuthContext);
15+
16+
const Protected = () => {
17+
if (!signed) {
18+
signOut();
19+
return <Navigate to={ROUTES.ROOT} replace />;
20+
}
21+
return <Outlet />;
22+
};
23+
24+
return useRoutes([
25+
{
26+
path: ROUTES.ROOT,
27+
element: !signed
28+
? <Landing />
29+
: signed && !selectedClientRoles
30+
? <LoginOrgSelection />
31+
: <Protected />,
32+
children: signed && selectedClientRoles
33+
? [{ element: <Layout />, children: BrowserRoutes }]
34+
: undefined
35+
},
36+
{ path: ROUTES.SERVICE_STATUS, element: <ServiceStatus /> },
37+
{ path: ROUTES.FOUR_OH_FOUR, element: <FourOhFour /> },
38+
{ path: '*', element: <FourOhFour /> }
39+
]);
40+
};
41+
42+
export default AppRoutes;

0 commit comments

Comments
 (0)