MSP-3107 update permissions logic

This commit is contained in:
veselovnk committed 2024-04-18 11:09:13 +03:00
1 parent 90e9485f19
commit d63afbfcd0
4 files changed
+17 -9

No files matched your search

+11
View File
@@ -4,9 +4,16 @@ import { localStorageKeys } from '@constants/localStorageKeys.ts'
import { LocalStorage } from '@utils/localStorageUtils.ts'
import useRole from '@hooks/useRole.tsx'
import { routePaths } from '@routes/routePaths.ts'
import { PermissionKeys } from '@type/roles.type.ts'
const PrivateRoute = () => {
const { hasPermission } = useRole()
const location = useLocation()
const userToken = LocalStorage.get(localStorageKeys.USER_TOKEN)
@@ -15,6 +22,10 @@ const PrivateRoute = () => {
return <Navigate to={routePaths.login} replace />
}
if ( location.pathname !=='/' && !hasPermission(PermissionKeys.read)) {
return <Navigate to={routePaths.home} replace />
}
return <Outlet />
}