|
| 1 | +import React from 'react' |
| 2 | +import Head from 'next/head' |
| 3 | +import styles from '../styles/Home.module.css' |
| 4 | +import EmailPassword from 'supertokens-auth-react/recipe/emailpassword' |
| 5 | +import dynamic from 'next/dynamic' |
| 6 | + |
| 7 | +const EmailPasswordAuthNoSSR = dynamic( |
| 8 | + () => Promise.resolve().then(() => EmailPassword.EmailPasswordAuth), |
| 9 | + { |
| 10 | + ssr: false, |
| 11 | + } |
| 12 | +) |
| 13 | + |
| 14 | +export default function Home() { |
| 15 | + async function logoutClicked() { |
| 16 | + await EmailPassword.signOut() |
| 17 | + window.location.href = '/auth' |
| 18 | + } |
| 19 | + |
| 20 | + async function fetchUserData() { |
| 21 | + const res = await fetch('/api/user') |
| 22 | + const json = await res.json() |
| 23 | + alert(JSON.stringify(json)) |
| 24 | + } |
| 25 | + |
| 26 | + return ( |
| 27 | + <div className={styles.container}> |
| 28 | + <Head> |
| 29 | + <title>SuperTokens 💫</title> |
| 30 | + <link rel="icon" href="/favicon.ico" /> |
| 31 | + </Head> |
| 32 | + |
| 33 | + <main className={styles.main}> |
| 34 | + <h1 className={styles.title}> |
| 35 | + Welcome to <a href="https://nextjs.org">Next.js!</a> |
| 36 | + </h1> |
| 37 | + <EmailPasswordAuthNoSSR> |
| 38 | + <p className={styles.description}> |
| 39 | + You are authenticated with SuperTokens! |
| 40 | + </p> |
| 41 | + |
| 42 | + <div |
| 43 | + style={{ |
| 44 | + display: 'flex', |
| 45 | + height: '70px', |
| 46 | + alignItems: 'center', |
| 47 | + justifyContent: 'flex-end', |
| 48 | + paddingLeft: '75px', |
| 49 | + paddingRight: '75px', |
| 50 | + }} |
| 51 | + > |
| 52 | + <div |
| 53 | + onClick={logoutClicked} |
| 54 | + style={{ |
| 55 | + display: 'flex', |
| 56 | + width: '116px', |
| 57 | + height: '42px', |
| 58 | + backgroundColor: '#000000', |
| 59 | + borderRadius: '10px', |
| 60 | + cursor: 'pointer', |
| 61 | + alignItems: 'center', |
| 62 | + justifyContent: 'center', |
| 63 | + color: '#ffffff', |
| 64 | + fontWeight: 'bold', |
| 65 | + }} |
| 66 | + > |
| 67 | + SIGN OUT |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + <div |
| 71 | + style={{ |
| 72 | + display: 'flex', |
| 73 | + height: '70px', |
| 74 | + alignItems: 'center', |
| 75 | + justifyContent: 'flex-end', |
| 76 | + paddingLeft: '75px', |
| 77 | + paddingRight: '75px', |
| 78 | + }} |
| 79 | + > |
| 80 | + <div |
| 81 | + onClick={fetchUserData} |
| 82 | + style={{ |
| 83 | + display: 'flex', |
| 84 | + width: '150px', |
| 85 | + height: '42px', |
| 86 | + backgroundColor: 'rgb(247 54 54)', |
| 87 | + borderRadius: '10px', |
| 88 | + cursor: 'pointer', |
| 89 | + alignItems: 'center', |
| 90 | + justifyContent: 'center', |
| 91 | + color: '#ffffff', |
| 92 | + fontWeight: 'bold', |
| 93 | + }} |
| 94 | + > |
| 95 | + FETCH USER API |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + </EmailPasswordAuthNoSSR> |
| 99 | + |
| 100 | + <div className={styles.grid}> |
| 101 | + <a href="https://nextjs.org/docs" className={styles.card}> |
| 102 | + <h3>Documentation →</h3> |
| 103 | + <p>Find in-depth information about Next.js features and API.</p> |
| 104 | + </a> |
| 105 | + |
| 106 | + <a href="https://nextjs.org/learn" className={styles.card}> |
| 107 | + <h3>Learn →</h3> |
| 108 | + <p>Learn about Next.js in an interactive course with quizzes!</p> |
| 109 | + </a> |
| 110 | + |
| 111 | + <a |
| 112 | + href="https://github.com/vercel/next.js/tree/master/examples" |
| 113 | + className={styles.card} |
| 114 | + > |
| 115 | + <h3>Examples →</h3> |
| 116 | + <p>Discover and deploy boilerplate example Next.js projects.</p> |
| 117 | + </a> |
| 118 | + |
| 119 | + <a |
| 120 | + href="https://vercel.com/import?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" |
| 121 | + className={styles.card} |
| 122 | + > |
| 123 | + <h3>Deploy →</h3> |
| 124 | + <p> |
| 125 | + Instantly deploy your Next.js site to a public URL with Vercel. |
| 126 | + </p> |
| 127 | + </a> |
| 128 | + </div> |
| 129 | + </main> |
| 130 | + |
| 131 | + <footer className={styles.footer}> |
| 132 | + <a |
| 133 | + href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" |
| 134 | + target="_blank" |
| 135 | + rel="noopener noreferrer" |
| 136 | + > |
| 137 | + Powered by{' '} |
| 138 | + <img src="/vercel.svg" alt="Vercel Logo" className={styles.logo} /> |
| 139 | + </a> |
| 140 | + </footer> |
| 141 | + </div> |
| 142 | + ) |
| 143 | +} |
0 commit comments