|
| 1 | +import * as React from 'react'; |
| 2 | +import * as Server from '@common/server'; |
| 3 | +import ActionItem from '@system/documents/ActionItem'; |
| 4 | +import Button from '@system/Button'; |
| 5 | +import Cookies from 'js-cookie'; |
| 6 | +import GlobalModalManager from '@system/modals/GlobalModalManager'; |
| 7 | +import KeyHeader from '@system/KeyHeader'; |
| 8 | +import Page from '@components/Page'; |
| 9 | +import ThinAppLayout from '@system/layouts/ThinAppLayout'; |
| 10 | +import { FormHeading, FormParagraph, InputLabel } from '@system/typography/forms'; |
| 11 | + |
| 12 | +function ExampleAuthentication(props) { |
| 13 | + const [currentUser, setUser] = React.useState<Record<string, any> | null>(props.viewer); |
| 14 | + const [key, setKey] = React.useState<string>(props.sessionKey); |
| 15 | + const [loading, setLoading] = React.useState<boolean>(false); |
| 16 | + |
| 17 | + if (props.viewer) { |
| 18 | + return ( |
| 19 | + <Page |
| 20 | + title="wireframes.internet.dev ➝ features ➝ authentication ➝ you have a session" |
| 21 | + description="A lightweight website template to test our design system. You can view this template on GitHub and see how we write websites." |
| 22 | + url="https://wireframes.internet.dev/examples/features/authentication/apple" |
| 23 | + > |
| 24 | + <KeyHeader onInputChange={setKey} value={key} viewer={currentUser} /> |
| 25 | + <ThinAppLayout> |
| 26 | + <FormHeading style={{ marginTop: 64 }}>You have a session</FormHeading> |
| 27 | + <FormParagraph> |
| 28 | + Would you like to sign out? This example demonstrates detecting whether you have a cookie and signing you in if you are the authenticated user. |
| 29 | + </FormParagraph> |
| 30 | + <FormParagraph> |
| 31 | + By signing out, your cookie and session key will be deleted, and you will have to reauthenticate. After clicking "Sign out," you will see the sign-in form again. |
| 32 | + </FormParagraph> |
| 33 | + <Button |
| 34 | + loading={loading} |
| 35 | + onClick={async () => { |
| 36 | + const confirm = window.confirm('Are you sure?'); |
| 37 | + if (!confirm) { |
| 38 | + return; |
| 39 | + } |
| 40 | + |
| 41 | + Cookies.remove('sitekey'); |
| 42 | + window.location.reload(); |
| 43 | + }} |
| 44 | + style={{ marginTop: 24, width: '100%' }} |
| 45 | + > |
| 46 | + Sign out |
| 47 | + </Button> |
| 48 | + <div style={{ marginTop: 16 }}> |
| 49 | + <ActionItem icon={`⭢`} href="/examples/features/settings"> |
| 50 | + View settings |
| 51 | + </ActionItem> |
| 52 | + </div> |
| 53 | + </ThinAppLayout> |
| 54 | + <GlobalModalManager /> |
| 55 | + </Page> |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + return ( |
| 60 | + <Page |
| 61 | + title="wireframes.internet.dev ➝ features ➝ authentication ➝ apple" |
| 62 | + description="A lightweight website template to test our design system. You can view this template on GitHub and see how we write websites." |
| 63 | + url="https://wireframes.internet.dev/examples/features/authentication/apple" |
| 64 | + > |
| 65 | + <KeyHeader onInputChange={setKey} value={key} viewer={props.viewer} /> |
| 66 | + <ThinAppLayout> |
| 67 | + <FormHeading style={{ marginTop: 64 }}>Sign in with Apple</FormHeading> |
| 68 | + <FormParagraph>Enhance your experience by signing in with Apple. Simply click the button below.</FormParagraph> |
| 69 | + <Button href="https://api.internet.dev/authenticate-apple?domain=REDIRECT_WIREFRAMES_INTERNET_DEV" style={{ marginTop: 24, width: '100%' }}> |
| 70 | + Sign in with Apple |
| 71 | + </Button> |
| 72 | + |
| 73 | + {!currentUser ? ( |
| 74 | + <> |
| 75 | + <FormParagraph style={{ marginTop: 32 }}>If you our Services through these wireframes you agree to the following: </FormParagraph> |
| 76 | + <div style={{ marginTop: 16 }}> |
| 77 | + <ActionItem icon={`⊹`} href="https://txt.dev/wwwjim/intdev-acceptable-use" target="_blank"> |
| 78 | + Acceptable Use Policy |
| 79 | + </ActionItem> |
| 80 | + <ActionItem icon={`⊹`} href="https://txt.dev/wwwjim/intdev-terms-of-service" target="_blank"> |
| 81 | + Terms of Service |
| 82 | + </ActionItem> |
| 83 | + <ActionItem icon={`⊹`} href="https://txt.dev/wwwjim/intdev-privacy-policy" target="_blank"> |
| 84 | + Privacy Policy |
| 85 | + </ActionItem> |
| 86 | + </div> |
| 87 | + </> |
| 88 | + ) : null} |
| 89 | + </ThinAppLayout> |
| 90 | + <GlobalModalManager /> |
| 91 | + </Page> |
| 92 | + ); |
| 93 | +} |
| 94 | + |
| 95 | +export async function getServerSideProps(context) { |
| 96 | + const { sessionKey, viewer } = await Server.setup(context); |
| 97 | + |
| 98 | + return { |
| 99 | + props: { sessionKey, viewer }, |
| 100 | + }; |
| 101 | +} |
| 102 | + |
| 103 | +export default ExampleAuthentication; |
0 commit comments