From c8361f1748d73bdc0633c2762ab478706fb2e25d Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Wed, 20 Jul 2022 01:59:14 -0700 Subject: [PATCH] Make it so that if you sign in on / you get redirected to /home (#672) --- web/pages/index.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/web/pages/index.tsx b/web/pages/index.tsx index 44683a4f..d9ff7f51 100644 --- a/web/pages/index.tsx +++ b/web/pages/index.tsx @@ -1,5 +1,6 @@ -import React from 'react' - +import React, { useEffect } from 'react' +import { useRouter } from 'next/router' +import { useUser } from 'web/hooks/use-user' import { Contract, getContractsBySlugs } from 'web/lib/firebase/contracts' import { Page } from 'web/components/page' import { LandingPagePanel } from 'web/components/landing-page-panel' @@ -26,6 +27,17 @@ export const getServerSideProps = redirectIfLoggedIn('/home', async (_) => { export default function Home(props: { hotContracts: Contract[] }) { const { hotContracts } = props + + // for now this redirect in the component is how we handle the case where they are + // on this page and they log in -- in the future we will make some cleaner way + const user = useUser() + const router = useRouter() + useEffect(() => { + if (user != null) { + router.replace('/home') + } + }, [router, user]) + return (