|
1 |
| -import React from "react" |
2 |
| -import "./App.css" |
3 |
| -import { useIdentityContext, IdentityContextProvider } from "react-netlify-identity-widget" |
4 |
| -import "react-netlify-identity-widget/styles.css" |
| 1 | +import React from 'react' |
| 2 | +import './App.css' |
| 3 | +import { IdentityModal, useIdentityContext, IdentityContextProvider } from 'react-netlify-identity-widget' |
| 4 | +import 'react-netlify-identity-widget/styles.css' |
5 | 5 |
|
6 | 6 | function App() {
|
7 | 7 | const url = process.env.REACT_APP_NETLIFY_IDENTITY_URL // should look something like "https://foo.netlify.com"
|
8 |
| - if (!url) throw new Error('process.env.REACT_APP_NETLIFY_IDENTITY_URL is blank, which means you probably forgot to set it in your Netlify environment variables') |
| 8 | + if (!url) |
| 9 | + throw new Error( |
| 10 | + 'process.env.REACT_APP_NETLIFY_IDENTITY_URL is blank, which means you probably forgot to set it in your Netlify environment variables', |
| 11 | + ) |
9 | 12 | return (
|
10 | 13 | <IdentityContextProvider url={url}>
|
11 | 14 | <AuthStatusView />
|
12 | 15 | </IdentityContextProvider>
|
13 | 16 | )
|
14 | 17 | }
|
15 | 18 |
|
16 |
| -// code split the modal til you need it! |
17 |
| -const IdentityModal = React.lazy(() => import("react-netlify-identity-widget")) |
| 19 | +// // code split the modal til you need it! |
| 20 | +// const IdentityModal = React.lazy(() => import('react-netlify-identity-widget')) |
18 | 21 |
|
19 | 22 | function AuthStatusView() {
|
20 | 23 | const identity = useIdentityContext()
|
21 | 24 | const [dialog, setDialog] = React.useState(false)
|
22 | 25 | const name =
|
23 |
| - (identity && identity.user && identity.user.user_metadata && identity.user.user_metadata.full_name) || "NoName" |
| 26 | + (identity && identity.user && identity.user.user_metadata && identity.user.user_metadata.full_name) || 'NoName' |
24 | 27 | const avatar_url = identity && identity.user && identity.user.user_metadata && identity.user.user_metadata.avatar_url
|
25 | 28 | return (
|
26 | 29 | <div className="App">
|
27 | 30 | <header className="App-header">
|
28 | 31 | {identity && identity.isLoggedIn ? (
|
29 | 32 | <>
|
30 | 33 | <h1> hello {name}!</h1>
|
31 |
| - {avatar_url && <img alt="user name" src={avatar_url} style={{ height: 100, borderRadius: "50%" }} />} |
32 |
| - <button className="btn" style={{ maxWidth: 400, background: "orangered" }} onClick={() => setDialog(true)}> |
| 34 | + {avatar_url && <img alt="user name" src={avatar_url} style={{ height: 100, borderRadius: '50%' }} />} |
| 35 | + <button className="btn" style={{ maxWidth: 400, background: 'orangered' }} onClick={() => setDialog(true)}> |
33 | 36 | LOG OUT
|
34 | 37 | </button>
|
35 | 38 | </>
|
36 | 39 | ) : (
|
37 | 40 | <>
|
38 | 41 | <h1> hello! try logging in! </h1>
|
39 |
| - <button className="btn" style={{ maxWidth: 400, background: "darkgreen" }} onClick={() => setDialog(true)}> |
| 42 | + <button className="btn" style={{ maxWidth: 400, background: 'darkgreen' }} onClick={() => setDialog(true)}> |
40 | 43 | LOG IN
|
41 | 44 | </button>
|
42 | 45 | </>
|
43 | 46 | )}
|
44 | 47 |
|
45 |
| - <React.Suspense fallback="loading..."> |
46 |
| - <IdentityModal showDialog={dialog} onCloseDialog={() => setDialog(false)} /> |
47 |
| - </React.Suspense> |
| 48 | + <IdentityModal |
| 49 | + showDialog={dialog} |
| 50 | + onCloseDialog={() => setDialog(false)} |
| 51 | + onLogin={(user) => console.log('hello ', user!.user_metadata)} |
| 52 | + onSignup={(user) => console.log('welcome ', user!.user_metadata)} |
| 53 | + onLogout={() => console.log('bye ', name)} |
| 54 | + /> |
| 55 | + |
48 | 56 | <h3>
|
49 |
| - Or{" "} |
| 57 | + Or{' '} |
50 | 58 | <a
|
51 | 59 | href="https://github.com/sw-yx/react-netlify-identity-widget"
|
52 | 60 | target="_blank"
|
53 | 61 | rel="noopener noreferrer"
|
54 |
| - style={{ color: "powderblue" }} |
| 62 | + style={{ color: 'powderblue' }} |
55 | 63 | >
|
56 | 64 | view the source
|
57 | 65 | </a>
|
|
0 commit comments