Redirect home on sign in

This commit is contained in:
James Grugett 2022-08-07 07:41:31 -07:00
parent ffa74c8e10
commit 90c707516b

View File

@ -6,6 +6,9 @@ import { ManifoldLogo } from 'web/components/nav/manifold-logo'
import { redirectIfLoggedIn } from 'web/lib/firebase/server-auth'
import { useSaveReferral } from 'web/hooks/use-save-referral'
import { SEO } from 'web/components/SEO'
import { useUser } from 'web/hooks/use-user'
import { useEffect } from 'react'
import { useRouter } from 'next/router'
export const getServerSideProps = redirectIfLoggedIn('/home', async (_) => {
// These hardcoded markets will be shown in the frontpage for signed-out users:
@ -29,6 +32,15 @@ export default function Home(props: { hotContracts: Contract[] }) {
useSaveReferral()
const user = useUser()
const router = useRouter()
useEffect(() => {
if (user) {
// Redirect to the /home page if the user is logged in.
router.push('/home')
}
}, [user, router])
return (
<Page>
<SEO