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
2020-08-03 12:11:08 +02:00

18 lines
419 B
JavaScript

import { useContext } from 'react'
import { UserContext } from '../contexts/UserContext'
import redirect from '../utils/redirect'
const withoutAuth = (WrappedComponent) => {
const Component = (props) => {
const { isAuth, user } = useContext(UserContext)
if (isAuth) return redirect({}, `/users/${user.name}`)
return <WrappedComponent {...props} />
}
return Component
}
export default withoutAuth