@flaredev/cli 0.2.0 → 0.4.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.
- package/bin/flare.js +9 -1
- package/dist/index.js +991 -344
- package/package.json +2 -2
- package/templates/app/app/admin/page.tsx +9 -61
- package/templates/app/app/dashboard/account/layout.tsx +30 -0
- package/templates/app/app/dashboard/account/page.tsx +11 -31
- package/templates/app/app/dashboard/account/password/page.tsx +22 -0
- package/templates/app/app/dashboard/account/security/page.tsx +34 -0
- package/templates/app/app/dashboard/account/sessions/page.tsx +9 -0
- package/templates/app/app/dashboard/actions.ts +246 -0
- package/templates/app/app/dashboard/import-actions.ts +91 -0
- package/templates/app/app/dashboard/layout.tsx +66 -39
- package/templates/app/app/dashboard/observability/page.tsx +175 -0
- package/templates/app/app/dashboard/page.tsx +108 -27
- package/templates/app/app/verify-email/page.tsx +33 -0
- package/templates/app/components/account/account-nav.tsx +39 -0
- package/templates/app/components/account/{security-settings.tsx → sections.tsx} +507 -525
- package/templates/app/components/auth/otp-input.tsx +95 -0
- package/templates/app/components/auth/password-field.tsx +116 -0
- package/templates/app/components/auth/password-forms.tsx +76 -79
- package/templates/app/components/auth/sign-in-flow.tsx +306 -315
- package/templates/app/components/auth/sign-up-form.tsx +93 -101
- package/templates/app/components/auth/two-factor-form.tsx +139 -124
- package/templates/app/components/auth/use-resend.ts +44 -0
- package/templates/app/components/auth/verify-email-form.tsx +135 -0
- package/templates/app/components/dashboard/column-menu.tsx +66 -0
- package/templates/app/components/dashboard/dashboard-header.tsx +115 -0
- package/templates/app/components/dashboard/dashboard-sidebar.tsx +228 -0
- package/templates/app/components/dashboard/dropzone.tsx +92 -0
- package/templates/app/components/dashboard/editable.ts +12 -0
- package/templates/app/components/dashboard/export-button.tsx +41 -0
- package/templates/app/components/{admin → dashboard}/fields/file-field.tsx +22 -18
- package/templates/app/components/dashboard/import-dialog.tsx +540 -0
- package/templates/app/components/dashboard/inline-cell.tsx +165 -0
- package/templates/app/components/dashboard/local-time.tsx +77 -0
- package/templates/app/components/dashboard/page-header.tsx +57 -0
- package/templates/app/components/{admin → dashboard}/query.ts +2 -0
- package/templates/app/components/dashboard/record-actions.tsx +113 -0
- package/templates/app/components/dashboard/record-detail.tsx +200 -0
- package/templates/app/components/dashboard/resource-chart.tsx +91 -0
- package/templates/app/components/dashboard/resource-form-dialog.tsx +80 -0
- package/templates/app/components/{admin → dashboard}/resource-form-page.tsx +61 -55
- package/templates/app/components/{admin → dashboard}/resource-form.tsx +165 -139
- package/templates/app/components/dashboard/resource-stats.tsx +48 -0
- package/templates/app/components/{admin → dashboard}/resource-table.tsx +152 -28
- package/templates/app/components/{admin → dashboard}/row-actions.tsx +56 -11
- package/templates/app/components/dashboard/save-view-button.tsx +86 -0
- package/templates/app/components/dashboard/stat-card.tsx +69 -0
- package/templates/app/components/dashboard/table-selection.tsx +185 -0
- package/templates/app/components/dashboard/traffic-chart.tsx +32 -0
- package/templates/app/components/dashboard/user-menu.tsx +91 -0
- package/templates/app/components/ui/sonner.tsx +33 -13
- package/templates/app/db/flare-schema.ts +55 -1
- package/templates/app/lib/analytics.ts +121 -0
- package/templates/app/lib/api.ts +12 -0
- package/templates/app/lib/audit.ts +80 -0
- package/templates/app/lib/auth-config.ts +38 -33
- package/templates/app/lib/auth.ts +34 -0
- package/templates/app/lib/cache.ts +83 -83
- package/templates/app/lib/csv.ts +24 -0
- package/templates/app/lib/dashboard-nav.ts +15 -0
- package/templates/app/lib/dashboard.ts +165 -0
- package/templates/app/lib/password-rules.ts +159 -0
- package/templates/app/lib/site.ts +56 -47
- package/templates/app/lib/views.ts +29 -0
- package/templates/app/migrations/0000_init.sql +25 -2
- package/templates/app/migrations/meta/0000_snapshot.json +159 -1
- package/templates/app/migrations/meta/_journal.json +1 -1
- package/templates/app/vite.config.ts +41 -31
- package/templates/app/worker-configuration.d.ts +15764 -0
- package/templates/locks/package-lock.json +9189 -0
- package/templates/locks/pnpm-lock.yaml +6347 -0
- package/templates/locks/yarn.lock +3548 -0
- package/templates/app/app/admin/actions.ts +0 -113
- package/templates/app/app/admin/layout.tsx +0 -32
- package/templates/app/components/admin/admin-header.tsx +0 -78
- package/templates/app/components/admin/resource-nav.tsx +0 -120
- package/templates/app/components/dashboard/dashboard-nav.tsx +0 -35
- package/templates/app/lib/admin-nav.ts +0 -15
- package/templates/app/lib/admin.ts +0 -103
- /package/templates/app/components/{admin → dashboard}/fields/country-field.tsx +0 -0
- /package/templates/app/components/{admin → dashboard}/fields/date-field.tsx +0 -0
- /package/templates/app/components/{admin → dashboard}/fields/field-widget.tsx +0 -0
- /package/templates/app/components/{admin → dashboard}/fields/multi-select-field.tsx +0 -0
- /package/templates/app/components/{admin → dashboard}/fields/phone-field.tsx +0 -0
- /package/templates/app/components/{admin → dashboard}/fields/relation-field.tsx +0 -0
- /package/templates/app/components/{admin → dashboard}/resource-icon.tsx +0 -0
- /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 {
|
|
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
|
-
case "
|
|
35
|
-
return "
|
|
36
|
-
case "
|
|
37
|
-
|
|
38
|
-
case "
|
|
39
|
-
|
|
40
|
-
case "
|
|
41
|
-
return "That code
|
|
42
|
-
case "
|
|
43
|
-
return "
|
|
44
|
-
case "
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
case "
|
|
48
|
-
return "
|
|
49
|
-
|
|
50
|
-
return
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const [
|
|
67
|
-
const [
|
|
68
|
-
const [
|
|
69
|
-
const [
|
|
70
|
-
const [
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
</div>
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
className="flex flex-col gap-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
+
}
|