From 90c707516bd74b30097b0eddcb25a73081103699 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sun, 7 Aug 2022 07:41:31 -0700 Subject: [PATCH] Redirect home on sign in --- web/pages/index.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/web/pages/index.tsx b/web/pages/index.tsx index 473189aa..c1892939 100644 --- a/web/pages/index.tsx +++ b/web/pages/index.tsx @@ -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 (