Fixed #3502: Page is not getting redirected to 404 for non exist route. (#4246)

This commit is contained in:
darth-coder00 2022-04-20 12:56:20 +05:30 committed by GitHub
parent 098cb865d5
commit 1d3ba3e3a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 32 deletions

View File

@ -0,0 +1,33 @@
/*
* Copyright 2021 Collate
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { Redirect, Route, RouteProps } from 'react-router-dom';
import { useAuthContext } from '../authentication/auth-provider/AuthProvider';
import { ROUTES } from '../constants/constants';
import { useAuth } from '../hooks/authHooks';
const AdminProtectedRoute = (routeProps: RouteProps) => {
const { isAdminUser } = useAuth();
const { isAuthDisabled, isAuthenticated } = useAuthContext();
if (isAuthDisabled || isAdminUser) {
return <Route {...routeProps} />;
} else if (isAuthenticated) {
return <Redirect to={ROUTES.NOT_FOUND} />;
} else {
return <Redirect to={ROUTES.SIGNIN} />;
}
};
export default AdminProtectedRoute;

View File

@ -15,9 +15,7 @@ import { isEmpty } from 'lodash';
import React, { FunctionComponent } from 'react';
import { Redirect, Route, Switch } from 'react-router-dom';
import AppState from '../AppState';
import { useAuthContext } from '../authentication/auth-provider/AuthProvider';
import { ROUTES } from '../constants/constants';
import { useAuth } from '../hooks/authHooks';
import AddGlossaryPage from '../pages/AddGlossary/AddGlossaryPage.component';
import AddGlossaryTermPage from '../pages/AddGlossaryTermPage/AddGlossaryTermPage.component';
import AddServicePage from '../pages/AddServicePage/AddServicePage.component';
@ -45,10 +43,8 @@ import TourPageComponent from '../pages/tour-page/TourPage.component';
import UserListPage from '../pages/UserListPage/UserListPage';
import UserPage from '../pages/UserPage/UserPage.component';
import WebhooksPage from '../pages/WebhooksPage/WebhooksPage.component';
import AdminProtectedRoute from './AdminProtectedRoute';
const AuthenticatedAppRouter: FunctionComponent = () => {
const { isAdminUser } = useAuth();
const { isAuthDisabled } = useAuthContext();
return (
<Switch>
<Route exact component={MyDataPage} path={ROUTES.MY_DATA} />
@ -118,37 +114,41 @@ const AuthenticatedAppRouter: FunctionComponent = () => {
<Route exact component={EntityVersionPage} path={ROUTES.ENTITY_VERSION} />
<Route exact component={WebhooksPage} path={ROUTES.WEBHOOKS} />
<Route exact component={EditWebhookPage} path={ROUTES.EDIT_WEBHOOK} />
{/* <Route exact component={GlossaryPage} path={ROUTES.GLOSSARY} /> */}
<Route exact component={GlossaryPageV1} path={ROUTES.GLOSSARY} />
<Route exact component={GlossaryPageV1} path={ROUTES.GLOSSARY_DETAILS} />
<Route exact component={GlossaryPageV1} path={ROUTES.GLOSSARY_TERMS} />
{/* <Route
exact
component={GlossaryTermPage}
path={ROUTES.GLOSSARY_DETAILS}
/> */}
{/* <Route exact component={GlossaryTermPage} path={ROUTES.GLOSSARY_TERMS} /> */}
<Route exact component={UserPage} path={ROUTES.USER_PROFILE} />
{isAuthDisabled || isAdminUser ? (
<>
<Route exact component={AddGlossaryPage} path={ROUTES.ADD_GLOSSARY} />
<Route
exact
component={AddGlossaryTermPage}
path={ROUTES.ADD_GLOSSARY_TERMS_CHILD}
/>
<Route
exact
component={AddGlossaryTermPage}
path={ROUTES.ADD_GLOSSARY_TERMS}
/>
<Route exact component={AddWebhookPage} path={ROUTES.ADD_WEBHOOK} />
<Route exact component={RolesPage} path={ROUTES.ROLES} />
<Route exact component={CreateUserPage} path={ROUTES.CREATE_USER} />
<Route exact component={UserListPage} path={ROUTES.USER_LIST} />
</>
) : null}
<AdminProtectedRoute
exact
component={AddGlossaryPage}
path={ROUTES.ADD_GLOSSARY}
/>
<AdminProtectedRoute
exact
component={AddGlossaryTermPage}
path={ROUTES.ADD_GLOSSARY_TERMS_CHILD}
/>
<AdminProtectedRoute
exact
component={AddGlossaryTermPage}
path={ROUTES.ADD_GLOSSARY_TERMS}
/>
<AdminProtectedRoute
exact
component={AddWebhookPage}
path={ROUTES.ADD_WEBHOOK}
/>
<AdminProtectedRoute exact component={RolesPage} path={ROUTES.ROLES} />
<AdminProtectedRoute
exact
component={CreateUserPage}
path={ROUTES.CREATE_USER}
/>
<AdminProtectedRoute
exact
component={UserListPage}
path={ROUTES.USER_LIST}
/>
<Redirect to={ROUTES.NOT_FOUND} />
</Switch>
);