From 1d3ba3e3a1f2990e41bc42a0427aace77cd8fc50 Mon Sep 17 00:00:00 2001 From: darth-coder00 <86726556+darth-coder00@users.noreply.github.com> Date: Wed, 20 Apr 2022 12:56:20 +0530 Subject: [PATCH] Fixed #3502: Page is not getting redirected to 404 for non exist route. (#4246) --- .../ui/src/router/AdminProtectedRoute.tsx | 33 ++++++++++ .../ui/src/router/AuthenticatedAppRouter.tsx | 64 +++++++++---------- 2 files changed, 65 insertions(+), 32 deletions(-) create mode 100644 openmetadata-ui/src/main/resources/ui/src/router/AdminProtectedRoute.tsx diff --git a/openmetadata-ui/src/main/resources/ui/src/router/AdminProtectedRoute.tsx b/openmetadata-ui/src/main/resources/ui/src/router/AdminProtectedRoute.tsx new file mode 100644 index 00000000000..520d1dd47fb --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/router/AdminProtectedRoute.tsx @@ -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 ; + } else if (isAuthenticated) { + return ; + } else { + return ; + } +}; + +export default AdminProtectedRoute; diff --git a/openmetadata-ui/src/main/resources/ui/src/router/AuthenticatedAppRouter.tsx b/openmetadata-ui/src/main/resources/ui/src/router/AuthenticatedAppRouter.tsx index 2a5b1b5ffa9..c9ecb6b9c8b 100644 --- a/openmetadata-ui/src/main/resources/ui/src/router/AuthenticatedAppRouter.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/router/AuthenticatedAppRouter.tsx @@ -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 ( @@ -118,37 +114,41 @@ const AuthenticatedAppRouter: FunctionComponent = () => { - {/* */} - {/* */} - {/* */} - {isAuthDisabled || isAdminUser ? ( - <> - - - - - - - - - ) : null} - + + + + + + + );