-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
71 lines (63 loc) · 1.83 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import type { NextPage } from "next";
import Head from "next/head";
import styles from "../styles/Home.module.css";
import { usePicket } from "@picketapi/picket-react";
const Header = () => (
<Head>
<title>Picket Hello World</title>
<meta name="description" content="Saying hello to a web3 world" />
<link rel="icon" href="/favicon.ico" />
</Head>
);
const Home: NextPage = () => {
const { isAuthenticating, isAuthenticated, authState, logout, login, error } =
usePicket();
// user is logging in
if (isAuthenticating)
return (
<div className={styles.container}>
<Header />
<main className={styles.main}>
<h1 className={styles.title}>Connecting...</h1>
</main>
</div>
);
// user is not logged in
if (!isAuthenticated || !authState) {
return (
<div className={styles.container}>
<Header />
<main className={styles.main}>
<h1 className={styles.title}>Connect Your Wallet to Log In</h1>
<button
className={styles.connectWalletButton}
onClick={() => login()}
>
Log In with Your Wallet
</button>
{error && (
<p className={styles.error}>
{"msg" in error ? error.msg : error.toString()}
</p>
)}
</main>
</div>
);
}
// user is logged in 🎉
const { user, accessToken } = authState;
const { displayAddress } = user;
return (
<div className={styles.container}>
<Header />
<main className={styles.main}>
<h1 className={styles.title}>
You are logged in as {displayAddress} 🎉
</h1>
<code className={styles.accessToken}>{accessToken}</code>
<button onClick={() => logout()}>Logout</button>
</main>
</div>
);
};
export default Home;