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> )