From e9c183a493e698b5988501f5186356a23b22eb94 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 13 Dec 2021 10:20:31 -0800 Subject: [PATCH] Allow users to sign in from /account SQ --- web/lib/firebase/users.ts | 1 + web/pages/account.tsx | 91 ++++++++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 30 deletions(-) diff --git a/web/lib/firebase/users.ts b/web/lib/firebase/users.ts index e436b463..7b5428fa 100644 --- a/web/lib/firebase/users.ts +++ b/web/lib/firebase/users.ts @@ -65,6 +65,7 @@ export function listenForLogin(onUser: (_user: User | null) => void) { } else { // User logged out; reset to null onUser(null) + localStorage.removeItem(CACHED_USER_KEY) } }) } diff --git a/web/pages/account.tsx b/web/pages/account.tsx index 0fed1440..82d2c801 100644 --- a/web/pages/account.tsx +++ b/web/pages/account.tsx @@ -1,5 +1,4 @@ -import { useRouter } from 'next/router' -import { firebaseLogout } from '../lib/firebase/users' +import { firebaseLogin, firebaseLogout, User } from '../lib/firebase/users' import { Header } from '../components/header' import { useUser } from '../hooks/use-user' import { useState, useEffect } from 'react' @@ -7,11 +6,62 @@ import { Contract, listContracts } from '../lib/firebase/contracts' import { ContractsList } from '../components/contracts-list' import { Title } from '../components/title' +function UserCard(props: { user: User }) { + const { user } = props + return ( +
+
+ {user?.avatarUrl && ( + + )} +
+
+

{user?.name}

+

{user?.email}

+

M$ {user?.balance}

+
+ +
+
+
+ ) +} + +function SignInCard() { + return ( +
+
+ +
+
+

Welcome!

+

Sign in to get started

+
+ +
+
+
+ ) +} + export default function Account() { const user = useUser() - const router = useRouter() const [contracts, setContracts] = useState([]) useEffect(() => { + console.log('Fetching contracts', user?.id) if (user?.id) { listContracts(user?.id).then(setContracts) } @@ -21,34 +71,15 @@ export default function Account() {
-
-
-
- {user?.avatarUrl && ( - - )} -
-
-

{user?.name}

-

{user?.email}

-

M${user?.balance}

-
- -
-
+ {user ? ( +
+ + + <ContractsList contracts={contracts} /> </div> - </div> - - <Title text="Your markets" /> - <ContractsList contracts={contracts} /> + ) : ( + <SignInCard /> + )} </div> </div> )