From cd8245fbee8bd362c52369103544b06fdd5f3bbb Mon Sep 17 00:00:00 2001 From: mantikoros Date: Wed, 5 Oct 2022 21:38:13 -0500 Subject: [PATCH] redirect to /home after login --- web/pages/index.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/web/pages/index.tsx b/web/pages/index.tsx index 4013f57a..91572a16 100644 --- a/web/pages/index.tsx +++ b/web/pages/index.tsx @@ -1,3 +1,6 @@ +import { useEffect } from 'react' +import Router from 'next/router' + import { Contract, getTrendingContracts } from 'web/lib/firebase/contracts' import { Page } from 'web/components/page' import { LandingPagePanel } from 'web/components/landing-page-panel' @@ -6,6 +9,7 @@ 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' export const getServerSideProps = redirectIfLoggedIn('/home', async (_) => { const hotContracts = await getTrendingContracts() @@ -16,6 +20,7 @@ export default function Home(props: { hotContracts: Contract[] }) { const { hotContracts } = props useSaveReferral() + useRedirectAfterLogin() return ( @@ -35,3 +40,13 @@ export default function Home(props: { hotContracts: Contract[] }) { ) } + +const useRedirectAfterLogin = () => { + const user = useUser() + + useEffect(() => { + if (user) { + Router.replace('/home') + } + }, [user]) +}