23 lines
553 B
JavaScript
23 lines
553 B
JavaScript
// PublicRoute.js
|
|
import PropTypes from 'prop-types'
|
|
import { useContext } from 'react'
|
|
import { Navigate } from 'react-router-dom'
|
|
import { AuthContext } from './Dashboard/context/AuthContext'
|
|
|
|
const PublicRoute = ({ component: Component }) => {
|
|
const { authenticated } = useContext(AuthContext)
|
|
|
|
// Redirect to login if not authenticated
|
|
return !authenticated ? (
|
|
<Component />
|
|
) : (
|
|
<Navigate to='/dashboard/production/overview' />
|
|
)
|
|
}
|
|
|
|
PublicRoute.propTypes = {
|
|
component: PropTypes.func.isRequired
|
|
}
|
|
|
|
export default PublicRoute
|