@flaredev/cli 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/bin/flare.js +9 -1
  2. package/dist/index.js +751 -280
  3. package/package.json +2 -2
  4. package/templates/app/app/admin/page.tsx +9 -61
  5. package/templates/app/app/dashboard/account/page.tsx +6 -4
  6. package/templates/app/app/{admin → dashboard}/actions.ts +109 -11
  7. package/templates/app/app/dashboard/import-actions.ts +91 -0
  8. package/templates/app/app/dashboard/layout.tsx +42 -39
  9. package/templates/app/app/dashboard/observability/page.tsx +174 -0
  10. package/templates/app/app/dashboard/page.tsx +106 -25
  11. package/templates/app/app/verify-email/page.tsx +33 -0
  12. package/templates/app/components/account/security-settings.tsx +6 -9
  13. package/templates/app/components/auth/otp-input.tsx +95 -0
  14. package/templates/app/components/auth/password-field.tsx +116 -0
  15. package/templates/app/components/auth/password-forms.tsx +76 -79
  16. package/templates/app/components/auth/sign-in-flow.tsx +306 -315
  17. package/templates/app/components/auth/sign-up-form.tsx +93 -101
  18. package/templates/app/components/auth/two-factor-form.tsx +139 -124
  19. package/templates/app/components/auth/use-resend.ts +44 -0
  20. package/templates/app/components/auth/verify-email-form.tsx +135 -0
  21. package/templates/app/components/{admin/admin-header.tsx → dashboard/dashboard-header.tsx} +78 -78
  22. package/templates/app/components/{admin/resource-nav.tsx → dashboard/dashboard-sidebar.tsx} +166 -120
  23. package/templates/app/components/dashboard/export-button.tsx +41 -0
  24. package/templates/app/components/{admin → dashboard}/fields/file-field.tsx +302 -302
  25. package/templates/app/components/dashboard/import-dialog.tsx +487 -0
  26. package/templates/app/components/dashboard/page-header.tsx +57 -0
  27. package/templates/app/components/dashboard/resource-form-dialog.tsx +80 -0
  28. package/templates/app/components/{admin → dashboard}/resource-form-page.tsx +61 -55
  29. package/templates/app/components/{admin → dashboard}/resource-form.tsx +165 -139
  30. package/templates/app/components/dashboard/resource-stats.tsx +53 -0
  31. package/templates/app/components/{admin → dashboard}/resource-table.tsx +331 -281
  32. package/templates/app/components/{admin → dashboard}/row-actions.tsx +144 -111
  33. package/templates/app/components/dashboard/stat-card.tsx +69 -0
  34. package/templates/app/components/dashboard/table-selection.tsx +185 -0
  35. package/templates/app/components/dashboard/traffic-chart.tsx +32 -0
  36. package/templates/app/db/flare-schema.ts +33 -1
  37. package/templates/app/lib/analytics.ts +121 -0
  38. package/templates/app/lib/audit.ts +80 -0
  39. package/templates/app/lib/auth-config.ts +38 -33
  40. package/templates/app/lib/auth.ts +34 -0
  41. package/templates/app/lib/cache.ts +83 -83
  42. package/templates/app/lib/csv.ts +24 -0
  43. package/templates/app/lib/dashboard-nav.ts +15 -0
  44. package/templates/app/lib/{admin.ts → dashboard.ts} +138 -103
  45. package/templates/app/lib/password-rules.ts +159 -0
  46. package/templates/app/lib/site.ts +56 -47
  47. package/templates/app/migrations/0000_init.sql +15 -3
  48. package/templates/app/migrations/meta/0000_snapshot.json +97 -1
  49. package/templates/app/migrations/meta/_journal.json +1 -1
  50. package/templates/app/worker-configuration.d.ts +15764 -0
  51. package/templates/locks/package-lock.json +9189 -0
  52. package/templates/locks/pnpm-lock.yaml +6347 -0
  53. package/templates/app/app/admin/layout.tsx +0 -32
  54. package/templates/app/components/dashboard/dashboard-nav.tsx +0 -35
  55. package/templates/app/lib/admin-nav.ts +0 -15
  56. /package/templates/app/components/{admin → dashboard}/fields/country-field.tsx +0 -0
  57. /package/templates/app/components/{admin → dashboard}/fields/date-field.tsx +0 -0
  58. /package/templates/app/components/{admin → dashboard}/fields/field-widget.tsx +0 -0
  59. /package/templates/app/components/{admin → dashboard}/fields/multi-select-field.tsx +0 -0
  60. /package/templates/app/components/{admin → dashboard}/fields/phone-field.tsx +0 -0
  61. /package/templates/app/components/{admin → dashboard}/fields/relation-field.tsx +0 -0
  62. /package/templates/app/components/{admin → dashboard}/query.ts +0 -0
  63. /package/templates/app/components/{admin → dashboard}/resource-icon.tsx +0 -0
  64. /package/templates/app/components/{admin → dashboard}/resource-table-toolbar.tsx +0 -0
@@ -1,315 +1,306 @@
1
- "use client";
2
-
3
- import { useEffect, useRef, useState } from "react";
4
- import Link from "next/link";
5
- import { FingerprintIcon, MailIcon, KeyRoundIcon } from "lucide-react";
6
- import { authClient } from "@/lib/auth-client";
7
- import type { SocialProvider } from "@/lib/auth-config";
8
- import { AuthInput, AuthLabel, Divider, FormMessage, PrimaryButton, SecondaryButton, TextButton } from "./ui";
9
- import { SocialButtons } from "./social-buttons";
10
-
11
- export interface SignInMethods {
12
- magicLink: boolean;
13
- emailOtp: boolean;
14
- passkeys: boolean;
15
- }
16
-
17
- interface Props {
18
- providers: SocialProvider[];
19
- socialPlacement: "before" | "after";
20
- socialStyle: "full" | "icon";
21
- methods: SignInMethods;
22
- next: string;
23
- initialError?: string | null;
24
- initialNotice?: string | null;
25
- }
26
-
27
- type Step = "email" | "password" | "link-sent" | "code";
28
-
29
- /** Messages for Better Auth's error codes, written for the person signing in. */
30
- export function authErrorMessage(error: { code?: string; message?: string } | null | undefined, fallback = "Something went wrong. Try again."): string {
31
- switch (error?.code) {
32
- case "INVALID_EMAIL_OR_PASSWORD":
33
- return "That email and password don't match.";
34
- case "EMAIL_NOT_VERIFIED":
35
- return "Verify your email first: we've sent you a new link.";
36
- case "INVALID_OTP":
37
- case "INVALID_CODE":
38
- case "INVALID_TWO_FACTOR_CODE":
39
- return "That code isn't right. Check it and try again.";
40
- case "OTP_EXPIRED":
41
- return "That code has expired. Ask for a new one.";
42
- case "TOO_MANY_ATTEMPTS":
43
- return "Too many attempts. Ask for a new code.";
44
- case "USER_ALREADY_EXISTS":
45
- case "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL":
46
- return "An account with this email already exists. Sign in instead.";
47
- case "PASSWORD_TOO_SHORT":
48
- return "Use at least 8 characters.";
49
- default:
50
- return error?.message || fallback;
51
- }
52
- }
53
-
54
- const go = (next: string) => {
55
- window.location.href = next;
56
- };
57
-
58
- /**
59
- * Sign-in in two steps: the email first (with social and passkey sign-in beside it),
60
- * then the password or an emailed link or code. A password sign-in that needs a
61
- * second factor continues on /two-factor (see lib/auth-client.ts).
62
- */
63
- export function SignInFlow({ providers, socialPlacement, socialStyle, methods, next, initialError, initialNotice }: Props) {
64
- const [step, setStep] = useState<Step>("email");
65
- const [email, setEmail] = useState("");
66
- const [password, setPassword] = useState("");
67
- const [code, setCode] = useState("");
68
- const [pending, setPending] = useState<string | null>(null);
69
- const [error, setError] = useState<string | null>(initialError ?? null);
70
- const [notice, setNotice] = useState<string | null>(initialNotice ?? null);
71
- const passwordRef = useRef<HTMLInputElement>(null);
72
-
73
- // Offer saved passkeys in the email field's autofill (conditional UI), where supported.
74
- useEffect(() => {
75
- if (!methods.passkeys || typeof PublicKeyCredential === "undefined") return;
76
- let cancelled = false;
77
- PublicKeyCredential.isConditionalMediationAvailable?.().then((available) => {
78
- if (!available || cancelled) return;
79
- void authClient.signIn.passkey({ autoFill: true }).then(({ error }) => {
80
- if (!error) go(next);
81
- });
82
- });
83
- return () => {
84
- cancelled = true;
85
- };
86
- }, [methods.passkeys, next]);
87
-
88
- useEffect(() => {
89
- if (step === "password") passwordRef.current?.focus();
90
- }, [step]);
91
-
92
- const run = async (label: string, work: () => Promise<void>) => {
93
- setPending(label);
94
- setError(null);
95
- setNotice(null);
96
- try {
97
- await work();
98
- } finally {
99
- setPending(null);
100
- }
101
- };
102
-
103
- const signInWithPassword = () =>
104
- run("password", async () => {
105
- const { data, error } = await authClient.signIn.email({ email, password });
106
- if (error) return setError(authErrorMessage(error));
107
- // With two-factor on, the client plugin has already sent us to /two-factor.
108
- if (data && "twoFactorRedirect" in data && data.twoFactorRedirect) return;
109
- go(next);
110
- });
111
-
112
- const sendLink = () =>
113
- run("link", async () => {
114
- const { error } = await authClient.signIn.magicLink({ email, callbackURL: next, errorCallbackURL: "/sign-in?error=link" });
115
- if (error) return setError(authErrorMessage(error));
116
- setStep("link-sent");
117
- });
118
-
119
- const sendCode = () =>
120
- run("code", async () => {
121
- const { error } = await authClient.emailOtp.sendVerificationOtp({ email, type: "sign-in" });
122
- if (error) return setError(authErrorMessage(error));
123
- setCode("");
124
- setStep("code");
125
- });
126
-
127
- const signInWithCode = () =>
128
- run("verify", async () => {
129
- const { error } = await authClient.signIn.emailOtp({ email, otp: code.trim() });
130
- if (error) return setError(authErrorMessage(error));
131
- go(next);
132
- });
133
-
134
- const signInWithPasskey = () =>
135
- run("passkey", async () => {
136
- const { error } = await authClient.signIn.passkey();
137
- if (error) return setError(authErrorMessage(error, "That passkey didn't work. Try again or use your email."));
138
- go(next);
139
- });
140
-
141
- const social = (
142
- <SocialButtons providers={providers} variant={socialStyle} next={next} onError={setError} />
143
- );
144
- const hasSocial = providers.length > 0;
145
- const changeEmail = (
146
- <div className="flex items-center justify-between rounded-[calc(var(--radius)-2px)] bg-surface-muted px-3.5 py-2.5 text-sm">
147
- <span className="truncate text-foreground">{email}</span>
148
- <TextButton onClick={() => setStep("email")}>Change</TextButton>
149
- </div>
150
- );
151
-
152
- if (step === "link-sent") {
153
- return (
154
- <div className="flex flex-col gap-5 text-center">
155
- <span className="mx-auto grid size-12 place-items-center rounded-full bg-brand/15 text-link">
156
- <MailIcon className="size-6" />
157
- </span>
158
- <div className="flex flex-col gap-1.5">
159
- <p className="text-base font-medium text-foreground">Check your email</p>
160
- <p className="text-sm text-foreground-muted">
161
- We sent a sign-in link to <span className="font-medium text-foreground">{email}</span>. It works once and expires in 5 minutes.
162
- </p>
163
- </div>
164
- <FormMessage>{error}</FormMessage>
165
- <div className="flex justify-center gap-4">
166
- <TextButton onClick={sendLink} disabled={pending !== null}>Send it again</TextButton>
167
- <TextButton onClick={() => setStep("email")}>Use another email</TextButton>
168
- </div>
169
- </div>
170
- );
171
- }
172
-
173
- if (step === "code") {
174
- return (
175
- <form
176
- className="flex flex-col gap-4"
177
- onSubmit={(event) => {
178
- event.preventDefault();
179
- void signInWithCode();
180
- }}
181
- >
182
- <p className="text-sm text-foreground-muted">
183
- Enter the 6-digit code we sent to <span className="font-medium text-foreground">{email}</span>.
184
- </p>
185
- <div className="flex flex-col gap-2">
186
- <AuthLabel htmlFor="code">Code</AuthLabel>
187
- <AuthInput
188
- id="code"
189
- name="code"
190
- value={code}
191
- onChange={(event) => setCode(event.target.value.replace(/\D/g, "").slice(0, 6))}
192
- inputMode="numeric"
193
- autoComplete="one-time-code"
194
- pattern="\d{6}"
195
- placeholder="123456"
196
- className="text-center font-mono text-xl tracking-[0.5em]"
197
- autoFocus
198
- required
199
- aria-invalid={Boolean(error) || undefined}
200
- />
201
- </div>
202
- <FormMessage>{error}</FormMessage>
203
- <PrimaryButton type="submit" pending={pending === "verify"} disabled={code.length !== 6}>
204
- Sign in
205
- </PrimaryButton>
206
- <div className="flex justify-center gap-4">
207
- <TextButton onClick={sendCode} disabled={pending !== null}>Send a new code</TextButton>
208
- <TextButton onClick={() => setStep("email")}>Use another email</TextButton>
209
- </div>
210
- </form>
211
- );
212
- }
213
-
214
- if (step === "password") {
215
- return (
216
- <form
217
- className="flex flex-col gap-4"
218
- onSubmit={(event) => {
219
- event.preventDefault();
220
- void signInWithPassword();
221
- }}
222
- >
223
- {changeEmail}
224
- {/* Keeps the email with the password for password managers. */}
225
- <input type="email" name="email" value={email} autoComplete="username" readOnly hidden />
226
- <div className="flex flex-col gap-2">
227
- <div className="flex items-baseline justify-between">
228
- <AuthLabel htmlFor="password">Password</AuthLabel>
229
- <Link href={`/forgot-password?email=${encodeURIComponent(email)}`} className="text-sm text-link hover:underline">
230
- Forgot password?
231
- </Link>
232
- </div>
233
- <AuthInput
234
- ref={passwordRef}
235
- id="password"
236
- name="password"
237
- type="password"
238
- autoComplete="current-password"
239
- value={password}
240
- onChange={(event) => setPassword(event.target.value)}
241
- required
242
- aria-invalid={Boolean(error) || undefined}
243
- />
244
- </div>
245
- <FormMessage>{error}</FormMessage>
246
- <PrimaryButton type="submit" pending={pending === "password"}>
247
- Sign in
248
- </PrimaryButton>
249
- {(methods.magicLink || methods.emailOtp) && (
250
- <>
251
- <Divider />
252
- {methods.magicLink && (
253
- <SecondaryButton onClick={sendLink} disabled={pending !== null}>
254
- <MailIcon className="size-4" /> Email me a sign-in link
255
- </SecondaryButton>
256
- )}
257
- {methods.emailOtp && (
258
- <SecondaryButton onClick={sendCode} disabled={pending !== null}>
259
- <KeyRoundIcon className="size-4" /> Email me a code
260
- </SecondaryButton>
261
- )}
262
- </>
263
- )}
264
- </form>
265
- );
266
- }
267
-
268
- return (
269
- <div className="flex flex-col gap-4">
270
- {hasSocial && socialPlacement === "before" && (
271
- <>
272
- {social}
273
- <Divider />
274
- </>
275
- )}
276
- <form
277
- className="flex flex-col gap-4"
278
- onSubmit={(event) => {
279
- event.preventDefault();
280
- setError(null);
281
- setStep("password");
282
- }}
283
- >
284
- <div className="flex flex-col gap-2">
285
- <AuthLabel htmlFor="email">Email</AuthLabel>
286
- <AuthInput
287
- id="email"
288
- name="email"
289
- type="email"
290
- autoComplete="username webauthn"
291
- placeholder="you@example.com"
292
- value={email}
293
- onChange={(event) => setEmail(event.target.value)}
294
- required
295
- autoFocus
296
- />
297
- </div>
298
- <FormMessage tone="success">{notice}</FormMessage>
299
- <FormMessage>{error}</FormMessage>
300
- <PrimaryButton type="submit">Continue</PrimaryButton>
301
- </form>
302
- {methods.passkeys && (
303
- <SecondaryButton onClick={signInWithPasskey} disabled={pending !== null}>
304
- <FingerprintIcon className="size-4" /> Sign in with a passkey
305
- </SecondaryButton>
306
- )}
307
- {hasSocial && socialPlacement === "after" && (
308
- <>
309
- <Divider />
310
- {social}
311
- </>
312
- )}
313
- </div>
314
- );
315
- }
1
+ "use client";
2
+
3
+ import { useEffect, useRef, useState } from "react";
4
+ import Link from "next/link";
5
+ import { FingerprintIcon, MailIcon, KeyRoundIcon } from "lucide-react";
6
+ import { authClient } from "@/lib/auth-client";
7
+ import type { SocialProvider } from "@/lib/auth-config";
8
+ import { AuthInput, AuthLabel, Divider, FormMessage, PrimaryButton, SecondaryButton, TextButton } from "./ui";
9
+ import { OtpInput } from "./otp-input";
10
+ import { SocialButtons } from "./social-buttons";
11
+ import { useResend } from "./use-resend";
12
+
13
+ export interface SignInMethods {
14
+ magicLink: boolean;
15
+ emailOtp: boolean;
16
+ passkeys: boolean;
17
+ }
18
+
19
+ interface Props {
20
+ providers: SocialProvider[];
21
+ socialPlacement: "before" | "after";
22
+ socialStyle: "full" | "icon";
23
+ methods: SignInMethods;
24
+ next: string;
25
+ initialError?: string | null;
26
+ initialNotice?: string | null;
27
+ }
28
+
29
+ type Step = "email" | "password" | "link-sent" | "code";
30
+
31
+ /** Messages for Better Auth's error codes, written for the person signing in. */
32
+ export function authErrorMessage(error: { code?: string; message?: string } | null | undefined, fallback = "Something went wrong. Try again."): string {
33
+ switch (error?.code) {
34
+ case "INVALID_EMAIL_OR_PASSWORD":
35
+ return "That email and password don't match.";
36
+ case "EMAIL_NOT_VERIFIED":
37
+ return "Verify your email first: we've sent you a new link.";
38
+ case "INVALID_OTP":
39
+ case "INVALID_CODE":
40
+ case "INVALID_TWO_FACTOR_CODE":
41
+ return "That code isn't right. Check it and try again.";
42
+ case "OTP_EXPIRED":
43
+ return "That code has expired. Ask for a new one.";
44
+ case "TOO_MANY_ATTEMPTS":
45
+ return "Too many attempts. Ask for a new code.";
46
+ case "USER_ALREADY_EXISTS":
47
+ case "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL":
48
+ return "An account with this email already exists. Sign in instead.";
49
+ case "PASSWORD_TOO_SHORT":
50
+ return "Use at least 8 characters.";
51
+ default:
52
+ return error?.message || fallback;
53
+ }
54
+ }
55
+
56
+ const go = (next: string) => {
57
+ window.location.href = next;
58
+ };
59
+
60
+ /**
61
+ * Sign-in in two steps: the email first (with social and passkey sign-in beside it),
62
+ * then the password or an emailed link or code. A password sign-in that needs a
63
+ * second factor continues on /two-factor (see lib/auth-client.ts).
64
+ */
65
+ export function SignInFlow({ providers, socialPlacement, socialStyle, methods, next, initialError, initialNotice }: Props) {
66
+ const [step, setStep] = useState<Step>("email");
67
+ const [email, setEmail] = useState("");
68
+ const [password, setPassword] = useState("");
69
+ const [code, setCode] = useState("");
70
+ const [pending, setPending] = useState<string | null>(null);
71
+ const [error, setError] = useState<string | null>(initialError ?? null);
72
+ const [notice, setNotice] = useState<string | null>(initialNotice ?? null);
73
+ const passwordRef = useRef<HTMLInputElement>(null);
74
+
75
+ // Offer saved passkeys in the email field's autofill (conditional UI), where supported.
76
+ useEffect(() => {
77
+ if (!methods.passkeys || typeof PublicKeyCredential === "undefined") return;
78
+ let cancelled = false;
79
+ PublicKeyCredential.isConditionalMediationAvailable?.().then((available) => {
80
+ if (!available || cancelled) return;
81
+ void authClient.signIn.passkey({ autoFill: true }).then(({ error }) => {
82
+ if (!error) go(next);
83
+ });
84
+ });
85
+ return () => {
86
+ cancelled = true;
87
+ };
88
+ }, [methods.passkeys, next]);
89
+
90
+ useEffect(() => {
91
+ if (step === "password") passwordRef.current?.focus();
92
+ }, [step]);
93
+
94
+ const run = async (label: string, work: () => Promise<void>) => {
95
+ setPending(label);
96
+ setError(null);
97
+ setNotice(null);
98
+ try {
99
+ await work();
100
+ } finally {
101
+ setPending(null);
102
+ }
103
+ };
104
+
105
+ const signInWithPassword = () =>
106
+ run("password", async () => {
107
+ const { data, error } = await authClient.signIn.email({ email, password });
108
+ if (error) return setError(authErrorMessage(error));
109
+ // With two-factor on, the client plugin has already sent us to /two-factor.
110
+ if (data && "twoFactorRedirect" in data && data.twoFactorRedirect) return;
111
+ go(next);
112
+ });
113
+
114
+ const sendLink = () =>
115
+ run("link", async () => {
116
+ const { error } = await authClient.signIn.magicLink({ email, callbackURL: next, errorCallbackURL: "/sign-in?error=link" });
117
+ if (error) return setError(authErrorMessage(error));
118
+ setStep("link-sent");
119
+ });
120
+
121
+ const sendCode = () =>
122
+ run("code", async () => {
123
+ const { error } = await authClient.emailOtp.sendVerificationOtp({ email, type: "sign-in" });
124
+ if (error) return setError(authErrorMessage(error));
125
+ setCode("");
126
+ setStep("code");
127
+ });
128
+
129
+ // Resending leaves the code already in their inbox working; it just sends another.
130
+ const codeResend = useResend(sendCode);
131
+
132
+ const signInWithCode = () =>
133
+ run("verify", async () => {
134
+ const { error } = await authClient.signIn.emailOtp({ email, otp: code.trim() });
135
+ if (error) return setError(authErrorMessage(error));
136
+ go(next);
137
+ });
138
+
139
+ const signInWithPasskey = () =>
140
+ run("passkey", async () => {
141
+ const { error } = await authClient.signIn.passkey();
142
+ if (error) return setError(authErrorMessage(error, "That passkey didn't work. Try again or use your email."));
143
+ go(next);
144
+ });
145
+
146
+ const social = (
147
+ <SocialButtons providers={providers} variant={socialStyle} next={next} onError={setError} />
148
+ );
149
+ const hasSocial = providers.length > 0;
150
+ const changeEmail = (
151
+ <div className="flex items-center justify-between rounded-[calc(var(--radius)-2px)] bg-surface-muted px-3.5 py-2.5 text-sm">
152
+ <span className="truncate text-foreground">{email}</span>
153
+ <TextButton onClick={() => setStep("email")}>Change</TextButton>
154
+ </div>
155
+ );
156
+
157
+ if (step === "link-sent") {
158
+ return (
159
+ <div className="flex flex-col gap-5 text-center">
160
+ <span className="mx-auto grid size-12 place-items-center rounded-full bg-brand/15 text-link">
161
+ <MailIcon className="size-6" />
162
+ </span>
163
+ <div className="flex flex-col gap-1.5">
164
+ <p className="text-base font-medium text-foreground">Check your email</p>
165
+ <p className="text-sm text-foreground-muted">
166
+ We sent a sign-in link to <span className="font-medium text-foreground">{email}</span>. It works once and expires in 5 minutes.
167
+ </p>
168
+ </div>
169
+ <FormMessage>{error}</FormMessage>
170
+ <div className="flex justify-center gap-4">
171
+ <TextButton onClick={sendLink} disabled={pending !== null}>Send it again</TextButton>
172
+ <TextButton onClick={() => setStep("email")}>Use another email</TextButton>
173
+ </div>
174
+ </div>
175
+ );
176
+ }
177
+
178
+ if (step === "code") {
179
+ return (
180
+ <form
181
+ className="flex flex-col gap-4"
182
+ onSubmit={(event) => {
183
+ event.preventDefault();
184
+ void signInWithCode();
185
+ }}
186
+ >
187
+ <p className="text-sm text-foreground-muted">
188
+ Enter the 6-digit code we sent to <span className="font-medium text-foreground">{email}</span>.
189
+ </p>
190
+ <OtpInput value={code} onChange={setCode} onComplete={() => void signInWithCode()} label="Sign-in code" autoFocus disabled={pending === "verify"} />
191
+ <FormMessage>{error}</FormMessage>
192
+ <PrimaryButton type="submit" pending={pending === "verify"} disabled={code.length !== 6}>
193
+ Sign in
194
+ </PrimaryButton>
195
+ <div className="flex justify-center gap-4">
196
+ <TextButton onClick={() => void codeResend.resend()} disabled={codeResend.disabled || pending !== null}>
197
+ {codeResend.label}
198
+ </TextButton>
199
+ <TextButton onClick={() => setStep("email")}>Use another email</TextButton>
200
+ </div>
201
+ </form>
202
+ );
203
+ }
204
+
205
+ if (step === "password") {
206
+ return (
207
+ <form
208
+ className="flex flex-col gap-4"
209
+ onSubmit={(event) => {
210
+ event.preventDefault();
211
+ void signInWithPassword();
212
+ }}
213
+ >
214
+ {changeEmail}
215
+ {/* Keeps the email with the password for password managers. */}
216
+ <input type="email" name="email" value={email} autoComplete="username" readOnly hidden />
217
+ <div className="flex flex-col gap-2">
218
+ <div className="flex items-baseline justify-between">
219
+ <AuthLabel htmlFor="password">Password</AuthLabel>
220
+ <Link href={`/forgot-password?email=${encodeURIComponent(email)}`} className="text-sm text-link hover:underline">
221
+ Forgot password?
222
+ </Link>
223
+ </div>
224
+ <AuthInput
225
+ ref={passwordRef}
226
+ id="password"
227
+ name="password"
228
+ type="password"
229
+ autoComplete="current-password"
230
+ value={password}
231
+ onChange={(event) => setPassword(event.target.value)}
232
+ required
233
+ aria-invalid={Boolean(error) || undefined}
234
+ />
235
+ </div>
236
+ <FormMessage>{error}</FormMessage>
237
+ <PrimaryButton type="submit" pending={pending === "password"}>
238
+ Sign in
239
+ </PrimaryButton>
240
+ {(methods.magicLink || methods.emailOtp) && (
241
+ <>
242
+ <Divider />
243
+ {methods.magicLink && (
244
+ <SecondaryButton onClick={sendLink} disabled={pending !== null}>
245
+ <MailIcon className="size-4" /> Email me a sign-in link
246
+ </SecondaryButton>
247
+ )}
248
+ {methods.emailOtp && (
249
+ <SecondaryButton onClick={sendCode} disabled={pending !== null}>
250
+ <KeyRoundIcon className="size-4" /> Email me a code
251
+ </SecondaryButton>
252
+ )}
253
+ </>
254
+ )}
255
+ </form>
256
+ );
257
+ }
258
+
259
+ return (
260
+ <div className="flex flex-col gap-4">
261
+ {hasSocial && socialPlacement === "before" && (
262
+ <>
263
+ {social}
264
+ <Divider />
265
+ </>
266
+ )}
267
+ <form
268
+ className="flex flex-col gap-4"
269
+ onSubmit={(event) => {
270
+ event.preventDefault();
271
+ setError(null);
272
+ setStep("password");
273
+ }}
274
+ >
275
+ <div className="flex flex-col gap-2">
276
+ <AuthLabel htmlFor="email">Email</AuthLabel>
277
+ <AuthInput
278
+ id="email"
279
+ name="email"
280
+ type="email"
281
+ autoComplete="username webauthn"
282
+ placeholder="you@example.com"
283
+ value={email}
284
+ onChange={(event) => setEmail(event.target.value)}
285
+ required
286
+ autoFocus
287
+ />
288
+ </div>
289
+ <FormMessage tone="success">{notice}</FormMessage>
290
+ <FormMessage>{error}</FormMessage>
291
+ <PrimaryButton type="submit">Continue</PrimaryButton>
292
+ </form>
293
+ {methods.passkeys && (
294
+ <SecondaryButton onClick={signInWithPasskey} disabled={pending !== null}>
295
+ <FingerprintIcon className="size-4" /> Sign in with a passkey
296
+ </SecondaryButton>
297
+ )}
298
+ {hasSocial && socialPlacement === "after" && (
299
+ <>
300
+ <Divider />
301
+ {social}
302
+ </>
303
+ )}
304
+ </div>
305
+ );
306
+ }