-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add new auth system to fullstack example
- Loading branch information
Showing
4 changed files
with
126 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
examples/fullstack/contact-forms/src/pages/enroll-new-device.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
Button, | ||
FormControl, | ||
FormHelperText, | ||
FormLabel, | ||
Heading, | ||
Input, | ||
Stack, | ||
Text, | ||
} from '@chakra-ui/react' | ||
import { useE2ESDKClient } from '@socialgouv/e2esdk-react' | ||
import type { NextPage } from 'next' | ||
import React from 'react' | ||
|
||
const EnrollDevicePage: NextPage = () => { | ||
const [label, setLabel] = React.useState<string | undefined>() | ||
const [uri, setUri] = React.useState<string | undefined>() | ||
const client = useE2ESDKClient() | ||
const enroll = React.useCallback(async () => { | ||
const uri = await client.enrollNewDevice(label) | ||
setUri(uri) | ||
}, [label, client]) | ||
|
||
return ( | ||
<> | ||
<Heading as="h1">Enroll new device</Heading> | ||
<Stack spacing={4} mt={8}> | ||
{Boolean(uri) ? ( | ||
<Text fontFamily="mono" fontSize="xs"> | ||
{uri} | ||
</Text> | ||
) : ( | ||
<> | ||
<FormControl> | ||
<FormLabel>Device label</FormLabel> | ||
<Input | ||
fontFamily="mono" | ||
value={label} | ||
onChange={e => setLabel(e.target.value)} | ||
/> | ||
<FormHelperText> | ||
What shall we call the new device? | ||
</FormHelperText> | ||
</FormControl> | ||
<Button type="submit" onClick={enroll}> | ||
Enroll new device | ||
</Button> | ||
</> | ||
)} | ||
</Stack> | ||
</> | ||
) | ||
} | ||
|
||
export default EnrollDevicePage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
Button, | ||
FormControl, | ||
FormLabel, | ||
Heading, | ||
Input, | ||
Stack, | ||
} from '@chakra-ui/react' | ||
import { useE2ESDKClient } from '@socialgouv/e2esdk-react' | ||
import type { NextPage } from 'next' | ||
import { useRouter } from 'next/router' | ||
import React from 'react' | ||
|
||
const SignupPage: NextPage = () => { | ||
const [userId, setUserId] = React.useState('') | ||
const router = useRouter() | ||
const client = useE2ESDKClient() | ||
const signup = React.useCallback(async () => { | ||
await client.signup(userId) | ||
await router.push('/app/contact-forms') | ||
}, [userId, client, router]) | ||
|
||
return ( | ||
<> | ||
<Heading as="h1">Sign up</Heading> | ||
<Stack spacing={4} mt={8}> | ||
<FormControl> | ||
<FormLabel>User ID</FormLabel> | ||
<Input | ||
fontFamily="mono" | ||
value={userId} | ||
onChange={e => setUserId(e.target.value)} | ||
/> | ||
</FormControl> | ||
<Button type="submit" onClick={signup}> | ||
Sign up | ||
</Button> | ||
</Stack> | ||
</> | ||
) | ||
} | ||
|
||
export default SignupPage |