| 13 | * @returns {React.ReactElement} Children or unauthorized redirect |
| 14 | */ |
| 15 | const checkFeatureFlag = (features, display, children) => { |
| 16 | // Validate features object exists and is properly formatted |
| 17 | if (!features || Array.isArray(features) || Object.keys(features).length === 0) { |
| 18 | return <Navigate to='/unauthorized' replace /> |
| 19 | } |
| 20 | |
| 21 | // Check if feature flag exists and is enabled |
| 22 | if (Object.hasOwnProperty.call(features, display)) { |
| 23 | const isFeatureEnabled = features[display] === 'true' || features[display] === true |
| 24 | return isFeatureEnabled ? children : <Navigate to='/unauthorized' replace /> |
| 25 | } |
| 26 | |
| 27 | return <Navigate to='/unauthorized' replace /> |
| 28 | } |
| 29 | |
| 30 | export const RequireAuth = ({ permission, display, children }) => { |
| 31 | const location = useLocation() |