forked from workos/authkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.tsx
69 lines (58 loc) · 1.84 KB
/
page.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
'use client';
import { useFormState } from 'react-dom';
import { sendCode, verifyEmail } from './verify-email';
export default function VerifyEmail() {
// This example uses Next.js server actions to call functions on the server side.
//
// If your application is a single page app (SPA), you will need to:
// - handle the form submission in `<form onSubmit>`
// - make an API call to your backend (e.g using `fetch`)
const [sendCodeState, sendCodeAction] = useFormState(sendCode, { error: null });
const [verifyEmailState, verifyEmailAction] = useFormState(verifyEmail, { error: null });
if (!('user' in sendCodeState)) {
return (
<main key="email">
<h1>Verify email</h1>
<form action={sendCodeAction}>
<div>
<label htmlFor="email">Email</label>
<input
type="email"
name="email"
id="email"
autoCapitalize="off"
autoComplete="username"
autoFocus
required
/>
</div>
<button type="submit">Send code</button>
</form>
<pre>{JSON.stringify(sendCodeState, null, 2)}</pre>
</main>
);
}
return (
<main key="code">
<h1>Verify email</h1>
<form action={verifyEmailAction}>
<div>
<label htmlFor="code">Enter code from the email</label>
<input
type="text"
name="code"
id="code"
inputMode="numeric"
autoComplete="one-time-code"
pattern="^\d{6}$"
autoFocus
required
/>
</div>
<input type="hidden" name="userId" value={sendCodeState.user.id} />
<button type="submit">Continue</button>
</form>
<pre>{JSON.stringify(verifyEmailState, null, 2)}</pre>
</main>
);
}