UNPKG

react-garden

Version:

React + TypeScript + ThreeJS app using Material UI on NextJS, Apollo Client, GraphQL + WordPress REST APIs, for ThreeD web development.. a part of the threed.ai code family.

30 lines (24 loc) 641 B
// ** React Imports import { useEffect } from 'react' // ** Next Imports import { useRouter } from 'next/router' // ** Hooks Import import { useAuth } from '~/hooks/useAuth' const GuestGuard = props => { const { children, fallback } = props const auth = useAuth() const router = useRouter() useEffect(() => { if (!router.isReady) { return } if (window.localStorage.getItem('userData')) { router.replace('/') } }, [router.route]) if (auth.loading || (!auth.loading && auth.user !== null)) { return fallback } return <>{children}</> } export default GuestGuard