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.js
2020-04-23 17:53:39 +02:00

19 lines
475 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;