-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathpage.tsx
86 lines (73 loc) · 2.39 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use client';
import { useFormState } from 'react-dom';
import { sendReset, resetPassword } from './reset-password';
export default function ResetPassword({
searchParams,
}: {
searchParams: { token?: string; email?: string };
}) {
const { token, email } = searchParams;
// 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 [sendResetState, sendResetAction] = useFormState(sendReset, { error: null });
const [resetPasswordState, resetPasswordAction] = useFormState(resetPassword, { error: null });
if (!token) {
return (
<main key="email">
<h1>Reset password</h1>
<form action={sendResetAction}>
<div>
<label htmlFor="email">Email</label>
<input
type="email"
name="email"
id="email"
autoCapitalize="off"
autoComplete="username"
autoFocus
required
/>
</div>
<button type="submit">Send reset instructions</button>
</form>
<pre>{JSON.stringify(sendResetState, null, 2)}</pre>
</main>
);
}
return (
<main key="code">
<h1>Reset password</h1>
<form action={resetPasswordAction}>
<div>
<label htmlFor="newPassword">New Password</label>
<input
type="password"
name="newPassword"
id="newPassword"
autoCapitalize="off"
autoComplete="new-password"
autoFocus
required
/>
</div>
<input type="hidden" name="token" value={token} />
{email && (
// We also include the email in a hidden input so that password managers can update the password on the correct account.
// https://developer.1password.com/docs/web/compatible-website-design/#password-change-and-reset-forms
<input
type="text"
name="email"
value={email}
autoComplete="username"
style={{ display: 'none' }}
/>
)}
<button type="submit">Continue</button>
</form>
<pre>{JSON.stringify(resetPasswordState, null, 2)}</pre>
</main>
);
}