-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
36 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/admin-panel/src/authentication/VizBuilderPrivateRoute.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd | ||
*/ | ||
import React from 'react'; | ||
import { Navigate, Outlet, useLocation } from 'react-router-dom'; | ||
import { useUser } from '../api/queries'; | ||
import { AUTH_ROUTES } from '../routes'; | ||
|
||
export const VizBuilderPrivateRoute = () => { | ||
const location = useLocation(); | ||
const { isLoggedIn, isLoading, hasVizBuilderAccess } = useUser(); | ||
if (isLoading) return null; | ||
|
||
if (!isLoggedIn) { | ||
return <Navigate to={AUTH_ROUTES.LOGIN} state={{ from: location.pathname }} />; | ||
} | ||
|
||
if (!hasVizBuilderAccess) { | ||
return <Navigate to="/" state={{ from: location.pathname }} />; | ||
} | ||
|
||
return <Outlet />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters