Skip to content

Commit

Permalink
added check for authentication.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Jan 17, 2022
1 parent dd7d139 commit c7c5343
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/utilities/PrivateRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ export const PrivateRoute = ({ children, routeType }) => {
}

dispatch(updateAccessToken(profile))

const isAuthenticated = !!profile?.clientPrincipal && !error
const roles = profile?.clientPrincipal.userRoles
const isAuthenticated =
roles.includes('admin') || roles.includes('editor') || (roles.includes('readonly') && !error)
const isAdmin = profile?.clientPrincipal.userRoles.includes('admin')
if (routeType === 'admin') {
return !isAdmin ? <Navigate to="/403" /> : children
} else {
return !isAuthenticated ? <Navigate to="/login" /> : children
return !isAuthenticated ? <Navigate to="/403" /> : children
}
}

Expand Down

0 comments on commit c7c5343

Please sign in to comment.