From 3256482dcfa011f968b9158758d9bdce73ab78ed Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Wed, 17 Aug 2022 14:38:57 -0700 Subject: [PATCH] Make /home not kick out logged out users --- web/pages/home.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/web/pages/home.tsx b/web/pages/home.tsx index 1fd163ea..8153baea 100644 --- a/web/pages/home.tsx +++ b/web/pages/home.tsx @@ -12,15 +12,18 @@ import { getContractFromSlug } from 'web/lib/firebase/contracts' import { getUserAndPrivateUser } from 'web/lib/firebase/users' import { useTracking } from 'web/hooks/use-tracking' import { track } from 'web/lib/service/analytics' -import { redirectIfLoggedOut } from 'web/lib/firebase/server-auth' +import { authenticateOnServer } from 'web/lib/firebase/server-auth' import { useSaveReferral } from 'web/hooks/use-save-referral' +import { GetServerSideProps } from 'next' -export const getServerSideProps = redirectIfLoggedOut('/', async (_, creds) => { - return { props: { auth: await getUserAndPrivateUser(creds.user.uid) } } -}) +export const getServerSideProps: GetServerSideProps = async (ctx) => { + const creds = await authenticateOnServer(ctx) + const auth = creds ? await getUserAndPrivateUser(creds.user.uid) : null + return { props: { auth } } +} -const Home = (props: { auth: { user: User } }) => { - const { user } = props.auth +const Home = (props: { auth: { user: User } | null }) => { + const user = props.auth ? props.auth.user : null const [contract, setContract] = useContractPage() const router = useRouter()