-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2298 from KelvinTegelaar/dev
Dev to hotfix
- Loading branch information
Showing
22 changed files
with
2,073 additions
and
1,297 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
5.4.0 | ||
5.4.1 |
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 was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useLoadClientPrincipalQuery } from 'src/store/api/auth' | ||
import { useDispatch } from 'react-redux' | ||
import { updateAccessToken } from 'src/store/features/auth' | ||
import { Navigate } from 'react-router-dom' | ||
|
||
export const useAuthCheck = (allowedRoles) => { | ||
const dispatch = useDispatch() | ||
const { data: profile, isFetching } = useLoadClientPrincipalQuery() | ||
if (isFetching) { | ||
return { isLoading: true, component: null } | ||
} | ||
dispatch(updateAccessToken(profile)) | ||
let roles = profile?.clientPrincipal?.userRoles || [] | ||
|
||
if (!profile?.clientPrincipal) { | ||
return { | ||
component: ( | ||
<Navigate to={`/login?redirect_uri=${encodeURIComponent(window.location.href)}`} /> | ||
), | ||
result: false, | ||
} | ||
} | ||
if (allowedRoles && !allowedRoles.some((role) => roles.includes(role))) { | ||
return { component: <Navigate to="/403" />, result: true } | ||
} | ||
return { component: null, result: false } | ||
} |
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 |
---|---|---|
@@ -1,41 +1,20 @@ | ||
import React from 'react' | ||
import { Navigate } from 'react-router-dom' | ||
import { useLoadClientPrincipalQuery } from 'src/store/api/auth' | ||
import { FullScreenLoading } from 'src/components/utilities' | ||
import { useDispatch } from 'react-redux' | ||
import { updateAccessToken } from 'src/store/features/auth' | ||
import PropTypes from 'prop-types' | ||
import { useAuthCheck } from './CippauthCheck' | ||
|
||
export const PrivateRoute = ({ children, routeType }) => { | ||
const dispatch = useDispatch() | ||
const { data: profile, error, isFetching } = useLoadClientPrincipalQuery() | ||
//console.log() | ||
if (isFetching) { | ||
export const PrivateRoute = ({ children, allowedRoles }) => { | ||
const { isLoading, component: authComponent } = useAuthCheck(allowedRoles) | ||
if (isLoading) { | ||
return <FullScreenLoading /> | ||
} | ||
|
||
dispatch(updateAccessToken(profile)) | ||
let roles = null | ||
if (null !== profile?.clientPrincipal) { | ||
roles = profile?.clientPrincipal.userRoles | ||
} else if (null === profile?.clientPrincipal) { | ||
return <Navigate to={`/login?redirect_uri=${window.location.href}`} /> | ||
} | ||
if (null === roles) { | ||
return <Navigate to={`/login?redirect_uri=${window.location.href}`} /> | ||
} else { | ||
const isAuthenticated = | ||
roles.includes('admin') || roles.includes('editor') || (roles.includes('readonly') && !error) | ||
const isAdmin = roles.includes('admin') | ||
if (routeType === 'admin') { | ||
return !isAdmin ? <Navigate to="/403" /> : children | ||
} else { | ||
return !isAuthenticated ? <Navigate to="/403" /> : children | ||
} | ||
if (authComponent) { | ||
return authComponent | ||
} | ||
return children | ||
} | ||
|
||
PrivateRoute.propTypes = { | ||
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]), | ||
routeType: PropTypes.string, | ||
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]).isRequired, | ||
allowedRoles: PropTypes.arrayOf(PropTypes.string), | ||
} |
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
Oops, something went wrong.