This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/website/hoc/withoutAuth.jsx

18 lines
415 B
React
Raw Normal View History

2020-08-03 12:04:07 +02:00
import { useContext } from 'react'
import { UserContext } from '../contexts/UserContext'
import redirect from '../utils/redirect'
2020-08-03 14:14:45 +02:00
const withoutAuth = WrappedComponent => {
const Component = props => {
2020-08-03 12:04:07 +02:00
const { isAuth, user } = useContext(UserContext)
2020-08-03 12:04:07 +02:00
if (isAuth) return redirect({}, `/users/${user.name}`)
2020-08-03 12:04:07 +02:00
return <WrappedComponent {...props} />
}
2020-08-03 12:04:07 +02:00
return Component
}
export default withoutAuth