@alepha/ui 0.25.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/README.md +12 -0
- package/components.json +20 -0
- package/package.json +85 -0
- package/src/components/action-error-toaster/action-error-toaster.tsx +70 -0
- package/src/components/admin/admin-audits.tsx +247 -0
- package/src/components/admin/admin-files.tsx +346 -0
- package/src/components/admin/admin-jobs-executions-panel.tsx +235 -0
- package/src/components/admin/admin-jobs-status-badge.tsx +33 -0
- package/src/components/admin/admin-jobs.tsx +294 -0
- package/src/components/admin/admin-keys.tsx +162 -0
- package/src/components/admin/admin-notifications.tsx +130 -0
- package/src/components/admin/admin-page.tsx +24 -0
- package/src/components/admin/admin-parameters.tsx +864 -0
- package/src/components/admin/admin-payments.tsx +93 -0
- package/src/components/admin/admin-sessions.tsx +174 -0
- package/src/components/admin/admin-user-detail-audits-tab.tsx +82 -0
- package/src/components/admin/admin-user-detail-identity-aside.tsx +218 -0
- package/src/components/admin/admin-user-detail-overview-tab.tsx +87 -0
- package/src/components/admin/admin-user-detail-password-dialog.tsx +85 -0
- package/src/components/admin/admin-user-detail-password-schema.ts +11 -0
- package/src/components/admin/admin-user-detail-profile-schema.ts +19 -0
- package/src/components/admin/admin-user-detail-provider-labels.ts +15 -0
- package/src/components/admin/admin-user-detail-security-tab.tsx +146 -0
- package/src/components/admin/admin-user-detail-sessions-tab.tsx +93 -0
- package/src/components/admin/admin-user-detail.tsx +606 -0
- package/src/components/admin/admin-users-roles-picker.tsx +126 -0
- package/src/components/admin/admin-users-status-filter.tsx +51 -0
- package/src/components/admin/admin-users.tsx +518 -0
- package/src/components/admin/diff-lines.spec.ts +58 -0
- package/src/components/admin/diff-lines.ts +58 -0
- package/src/components/admin/parameter-diff-dialog.tsx +119 -0
- package/src/components/admin/parameter-history-item.tsx +252 -0
- package/src/components/admin/parameter-json-dialog.tsx +93 -0
- package/src/components/admin/parameter-save-dialog.tsx +126 -0
- package/src/components/admin/use-confirmed-action.tsx +93 -0
- package/src/components/alepha-table/__tests__/use-table-selection.browser.spec.tsx +92 -0
- package/src/components/alepha-table/alepha-table.tsx +1158 -0
- package/src/components/alepha-table/use-table-selection.ts +95 -0
- package/src/components/app-shell/app-shell.tsx +568 -0
- package/src/components/auth/__tests__/auth-router.spec.ts +52 -0
- package/src/components/auth/auth-login.tsx +382 -0
- package/src/components/auth/auth-register.tsx +786 -0
- package/src/components/auth/auth-reset-password.tsx +349 -0
- package/src/components/auth/auth-router.tsx +126 -0
- package/src/components/auth/auth-verify-email.tsx +179 -0
- package/src/components/auto-form/auto-form.tsx +867 -0
- package/src/components/brand-icon/brand-icon.tsx +104 -0
- package/src/components/button-dark/button-dark.tsx +78 -0
- package/src/components/button-language/button-language.tsx +98 -0
- package/src/components/button-theme/button-theme.tsx +148 -0
- package/src/components/button-user/button-user.tsx +214 -0
- package/src/components/captcha/turnstile-widget.tsx +157 -0
- package/src/components/control/control.tsx +735 -0
- package/src/components/control-array/control-array.tsx +700 -0
- package/src/components/control-base/__tests__/form-field-a11y.browser.spec.tsx +93 -0
- package/src/components/control-base/field-i18n.ts +60 -0
- package/src/components/control-base/form-field.tsx +275 -0
- package/src/components/control-base/grid.tsx +59 -0
- package/src/components/control-base/icon-hint.tsx +64 -0
- package/src/components/control-date/control-date.tsx +190 -0
- package/src/components/control-number/control-number.tsx +136 -0
- package/src/components/control-object/control-object.tsx +200 -0
- package/src/components/control-select/control-select.tsx +774 -0
- package/src/components/control-upload/control-upload.tsx +475 -0
- package/src/components/file-image/file-image.tsx +52 -0
- package/src/components/language-toggle/language-toggle.tsx +66 -0
- package/src/components/markdown-view/markdown-view.css +114 -0
- package/src/components/markdown-view/markdown-view.tsx +92 -0
- package/src/components/nav-shell/nav-page.tsx +56 -0
- package/src/components/nav-shell/nav-shell.tsx +72 -0
- package/src/components/nav-shell/nav-tree-util.ts +62 -0
- package/src/components/nav-shell/spotlight.tsx +163 -0
- package/src/components/nav-shell/use-nav-breadcrumbs.ts +52 -0
- package/src/components/nav-shell/use-nav-entries.ts +101 -0
- package/src/components/nav-shell/use-nav-tree.ts +61 -0
- package/src/components/ui/accordion.tsx +77 -0
- package/src/components/ui/alert-dialog.tsx +186 -0
- package/src/components/ui/alert.tsx +75 -0
- package/src/components/ui/aspect-ratio.tsx +22 -0
- package/src/components/ui/avatar.tsx +106 -0
- package/src/components/ui/badge.tsx +51 -0
- package/src/components/ui/breadcrumb.tsx +121 -0
- package/src/components/ui/button-group.tsx +86 -0
- package/src/components/ui/button.tsx +83 -0
- package/src/components/ui/calendar.tsx +235 -0
- package/src/components/ui/card.tsx +102 -0
- package/src/components/ui/carousel.tsx +241 -0
- package/src/components/ui/chart.tsx +370 -0
- package/src/components/ui/checkbox.tsx +27 -0
- package/src/components/ui/collapsible.tsx +19 -0
- package/src/components/ui/combobox.tsx +298 -0
- package/src/components/ui/command.tsx +196 -0
- package/src/components/ui/context-menu.tsx +271 -0
- package/src/components/ui/dialog.tsx +153 -0
- package/src/components/ui/direction.tsx +4 -0
- package/src/components/ui/drawer.tsx +130 -0
- package/src/components/ui/dropdown-menu.tsx +269 -0
- package/src/components/ui/empty.tsx +100 -0
- package/src/components/ui/hover-card.tsx +50 -0
- package/src/components/ui/input-group.tsx +157 -0
- package/src/components/ui/input-otp.tsx +83 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/item.tsx +200 -0
- package/src/components/ui/kbd.tsx +26 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/menubar.tsx +283 -0
- package/src/components/ui/navigation-menu.tsx +170 -0
- package/src/components/ui/pagination.tsx +133 -0
- package/src/components/ui/popover.tsx +87 -0
- package/src/components/ui/progress.tsx +82 -0
- package/src/components/ui/radio-group.tsx +35 -0
- package/src/components/ui/resizable.tsx +49 -0
- package/src/components/ui/scroll-area.tsx +51 -0
- package/src/components/ui/segmented.tsx +232 -0
- package/src/components/ui/select.tsx +201 -0
- package/src/components/ui/separator.tsx +22 -0
- package/src/components/ui/sheet.tsx +133 -0
- package/src/components/ui/sidebar.tsx +723 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +51 -0
- package/src/components/ui/sonner.tsx +46 -0
- package/src/components/ui/spinner.tsx +15 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/table.tsx +115 -0
- package/src/components/ui/tabs.tsx +79 -0
- package/src/components/ui/textarea.tsx +17 -0
- package/src/components/ui/toggle-group.tsx +86 -0
- package/src/components/ui/toggle.tsx +44 -0
- package/src/components/ui/tooltip.tsx +63 -0
- package/src/components/use-dialog/use-dialog.tsx +244 -0
- package/src/components/use-toast/use-toast.tsx +89 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/lib/__tests__/i18n-fr.spec.ts +72 -0
- package/src/lib/i18n-fr.ts +500 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles.css +129 -0
|
@@ -0,0 +1,786 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import { BrandIcon } from "@alepha/ui/components/brand-icon/brand-icon";
|
|
6
|
+
import {
|
|
7
|
+
TurnstileWidget,
|
|
8
|
+
type TurnstileWidgetHandle,
|
|
9
|
+
} from "@alepha/ui/components/captcha/turnstile-widget";
|
|
10
|
+
import { Control } from "@alepha/ui/components/control/control";
|
|
11
|
+
import { iconFor } from "@alepha/ui/components/control-base/icon-hint";
|
|
12
|
+
import { Alert, AlertDescription } from "@alepha/ui/components/ui/alert";
|
|
13
|
+
import { Button } from "@alepha/ui/components/ui/button";
|
|
14
|
+
import { Card, CardContent } from "@alepha/ui/components/ui/card";
|
|
15
|
+
import {
|
|
16
|
+
InputOTP,
|
|
17
|
+
InputOTPGroup,
|
|
18
|
+
InputOTPSeparator,
|
|
19
|
+
InputOTPSlot,
|
|
20
|
+
} from "@alepha/ui/components/ui/input-otp";
|
|
21
|
+
import { Label } from "@alepha/ui/components/ui/label";
|
|
22
|
+
import { Separator } from "@alepha/ui/components/ui/separator";
|
|
23
|
+
import { SchemaValidationError, z } from "alepha";
|
|
24
|
+
import type {
|
|
25
|
+
RealmConfig,
|
|
26
|
+
RegistrationIntentResponse,
|
|
27
|
+
UserController,
|
|
28
|
+
} from "alepha/api/users";
|
|
29
|
+
import { useClient } from "alepha/react";
|
|
30
|
+
import { useAuth } from "alepha/react/auth";
|
|
31
|
+
import { useForm, useFormState } from "alepha/react/form";
|
|
32
|
+
import { useI18n } from "alepha/react/i18n";
|
|
33
|
+
import { useRouter } from "alepha/react/router";
|
|
34
|
+
import { AlertCircle, Check, Info, X } from "lucide-react";
|
|
35
|
+
import {
|
|
36
|
+
type ReactNode,
|
|
37
|
+
useEffect,
|
|
38
|
+
useLayoutEffect,
|
|
39
|
+
useMemo,
|
|
40
|
+
useRef,
|
|
41
|
+
useState,
|
|
42
|
+
} from "react";
|
|
43
|
+
|
|
44
|
+
export interface AuthRegisterProps {
|
|
45
|
+
/**
|
|
46
|
+
* Realm configuration (drives required fields, verification step, OAuth buttons).
|
|
47
|
+
*/
|
|
48
|
+
realmConfig: RealmConfig;
|
|
49
|
+
/**
|
|
50
|
+
* Custom logo node, rendered above the form. When provided, it replaces
|
|
51
|
+
* the default `settings.logoUrl` <img>. Use this to inject a branded
|
|
52
|
+
* component (e.g. with light/dark variants or an animation).
|
|
53
|
+
*/
|
|
54
|
+
logo?: ReactNode;
|
|
55
|
+
/**
|
|
56
|
+
* Route to the login page. When set, a "Sign in" link is shown.
|
|
57
|
+
*/
|
|
58
|
+
loginPath?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Optional banner rendered above the registration form (form phase only).
|
|
61
|
+
* Used to contextualize the flow when the user arrives via a CTA, e.g.
|
|
62
|
+
* "Before creating a campaign, create an account."
|
|
63
|
+
*/
|
|
64
|
+
message?: ReactNode;
|
|
65
|
+
/**
|
|
66
|
+
* Where the "Cancel" button abandons to. Defaults to "/". This is
|
|
67
|
+
* intentionally decoupled from the post-auth `?redirect=` target: cancelling
|
|
68
|
+
* an unauthenticated registration must land somewhere public (home), not the
|
|
69
|
+
* protected destination the user was *heading* to — which would only bounce
|
|
70
|
+
* them back to this page.
|
|
71
|
+
*/
|
|
72
|
+
cancelPath?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type Phase = "form" | "verification";
|
|
76
|
+
|
|
77
|
+
interface State {
|
|
78
|
+
phase: Phase;
|
|
79
|
+
intent?: RegistrationIntentResponse;
|
|
80
|
+
credentials?: { identifier: string; password: string };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function AuthRegister(props: AuthRegisterProps) {
|
|
84
|
+
const auth = useAuth();
|
|
85
|
+
const userCtrl = useClient<UserController>();
|
|
86
|
+
const router = useRouter();
|
|
87
|
+
const { tr } = useI18n();
|
|
88
|
+
const redirect = router.query.redirect || "/";
|
|
89
|
+
// Surface upstream auth errors (e.g. failed OAuth callback redirects with
|
|
90
|
+
// `?error=...`) — same pattern as AuthLogin. Without this the user lands on
|
|
91
|
+
// a fresh-looking registration page with no clue why.
|
|
92
|
+
const queryError =
|
|
93
|
+
typeof router.query.error === "string" ? router.query.error : undefined;
|
|
94
|
+
|
|
95
|
+
const [state, setState] = useState<State>({ phase: "form" });
|
|
96
|
+
const [emailCode, setEmailCode] = useState("");
|
|
97
|
+
const [phoneCode, setPhoneCode] = useState("");
|
|
98
|
+
const [verifyError, setVerifyError] = useState<string | null>(null);
|
|
99
|
+
const [submitting, setSubmitting] = useState(false);
|
|
100
|
+
|
|
101
|
+
const captchaSiteKey = props.realmConfig.captchaSiteKey;
|
|
102
|
+
const [captchaToken, setCaptchaToken] = useState<string | undefined>();
|
|
103
|
+
const captchaRef = useRef<TurnstileWidgetHandle | null>(null);
|
|
104
|
+
// The `useForm` handler is memoized at form-create time, so it closes over
|
|
105
|
+
// the *initial* `captchaToken` (undefined). Mirror the latest value into a
|
|
106
|
+
// ref the handler can read at submission time.
|
|
107
|
+
const captchaTokenRef = useRef<string | undefined>(undefined);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
captchaTokenRef.current = captchaToken;
|
|
110
|
+
}, [captchaToken]);
|
|
111
|
+
|
|
112
|
+
const credentialsProvider = props.realmConfig.authenticationMethods.find(
|
|
113
|
+
(it) => it.type === "CREDENTIALS",
|
|
114
|
+
);
|
|
115
|
+
const settings = props.realmConfig.settings;
|
|
116
|
+
const allowed = settings.registrationAllowed !== false;
|
|
117
|
+
|
|
118
|
+
const schema = useMemo(() => {
|
|
119
|
+
const s = z.object({
|
|
120
|
+
firstName: z.text({ trim: true, maxLength: 100 }).optional(),
|
|
121
|
+
lastName: z.text({ trim: true, maxLength: 100 }).optional(),
|
|
122
|
+
username: z
|
|
123
|
+
.text({ trim: true, pattern: settings.usernameRegExp })
|
|
124
|
+
.optional(),
|
|
125
|
+
email: z.email().optional(),
|
|
126
|
+
phoneNumber: z.e164().optional(),
|
|
127
|
+
password: z.string().min(settings.passwordPolicy?.minLength ?? 8),
|
|
128
|
+
});
|
|
129
|
+
const required = z.schema.requiredKeys(s);
|
|
130
|
+
if (settings.firstNameLastName === "required") {
|
|
131
|
+
required.push("firstName", "lastName");
|
|
132
|
+
}
|
|
133
|
+
if (settings.username === "required") required.push("username");
|
|
134
|
+
if (settings.email === "required") required.push("email");
|
|
135
|
+
if (settings.phoneNumber === "required") required.push("phoneNumber");
|
|
136
|
+
return s;
|
|
137
|
+
}, [settings]);
|
|
138
|
+
|
|
139
|
+
const form = useForm({
|
|
140
|
+
schema,
|
|
141
|
+
handler: async (data) => {
|
|
142
|
+
try {
|
|
143
|
+
const intent = await userCtrl.createRegistrationIntent({
|
|
144
|
+
query: { userRealmName: props.realmConfig.realmName },
|
|
145
|
+
body: {
|
|
146
|
+
firstName: data.firstName,
|
|
147
|
+
lastName: data.lastName,
|
|
148
|
+
username: data.username,
|
|
149
|
+
email: data.email,
|
|
150
|
+
phoneNumber: data.phoneNumber,
|
|
151
|
+
password: data.password,
|
|
152
|
+
captchaToken: captchaSiteKey ? captchaTokenRef.current : undefined,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
const identifier = data.username ?? data.email ?? data.phoneNumber;
|
|
156
|
+
if (
|
|
157
|
+
intent.expectEmailVerification ||
|
|
158
|
+
intent.expectPhoneVerification ||
|
|
159
|
+
intent.expectCaptcha
|
|
160
|
+
) {
|
|
161
|
+
setState({
|
|
162
|
+
phase: "verification",
|
|
163
|
+
intent,
|
|
164
|
+
credentials: identifier
|
|
165
|
+
? { identifier, password: data.password }
|
|
166
|
+
: undefined,
|
|
167
|
+
});
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
await userCtrl.createUserFromIntent({
|
|
171
|
+
body: { intentId: intent.intentId },
|
|
172
|
+
});
|
|
173
|
+
if (identifier && credentialsProvider) {
|
|
174
|
+
await auth.login(credentialsProvider.name, {
|
|
175
|
+
username: identifier,
|
|
176
|
+
password: data.password,
|
|
177
|
+
realm: props.realmConfig.realmName,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
// `force: true` so parent-layout loaders re-run against the freshly
|
|
181
|
+
// authenticated user — see the note in auth-login.tsx.
|
|
182
|
+
await router.push(redirect, { force: true });
|
|
183
|
+
} catch (err) {
|
|
184
|
+
// Turnstile tokens are single-use — force a fresh challenge so the
|
|
185
|
+
// user can retry after a server-side failure.
|
|
186
|
+
captchaRef.current?.reset();
|
|
187
|
+
throw err;
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const formState = useFormState(form, ["error", "values", "loading"]);
|
|
193
|
+
const formError =
|
|
194
|
+
formState.error && !(formState.error instanceof SchemaValidationError)
|
|
195
|
+
? formState.error.message
|
|
196
|
+
: undefined;
|
|
197
|
+
const passwordValue = String(formState.values?.password ?? "");
|
|
198
|
+
|
|
199
|
+
const firstFieldId =
|
|
200
|
+
(settings.firstNameLastName !== "none" && form.input.firstName?.props.id) ||
|
|
201
|
+
(settings.username !== "none" &&
|
|
202
|
+
settings.username !== "email" &&
|
|
203
|
+
form.input.username?.props.id) ||
|
|
204
|
+
(settings.email !== "none" && form.input.email?.props.id) ||
|
|
205
|
+
(settings.phoneNumber !== "none" && form.input.phoneNumber?.props.id) ||
|
|
206
|
+
form.input.password.props.id;
|
|
207
|
+
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (state.phase !== "form" || !firstFieldId) return;
|
|
210
|
+
const el = document.getElementById(
|
|
211
|
+
String(firstFieldId),
|
|
212
|
+
) as HTMLInputElement | null;
|
|
213
|
+
el?.focus();
|
|
214
|
+
}, [state.phase, firstFieldId]);
|
|
215
|
+
|
|
216
|
+
const handleVerify = async () => {
|
|
217
|
+
if (!state.intent) return;
|
|
218
|
+
setSubmitting(true);
|
|
219
|
+
setVerifyError(null);
|
|
220
|
+
try {
|
|
221
|
+
await userCtrl.createUserFromIntent({
|
|
222
|
+
body: {
|
|
223
|
+
intentId: state.intent.intentId,
|
|
224
|
+
emailCode: state.intent.expectEmailVerification
|
|
225
|
+
? emailCode
|
|
226
|
+
: undefined,
|
|
227
|
+
phoneCode: state.intent.expectPhoneVerification
|
|
228
|
+
? phoneCode
|
|
229
|
+
: undefined,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
if (state.credentials && credentialsProvider) {
|
|
233
|
+
await auth.login(credentialsProvider.name, {
|
|
234
|
+
username: state.credentials.identifier,
|
|
235
|
+
password: state.credentials.password,
|
|
236
|
+
realm: props.realmConfig.realmName,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
// `force: true` so parent-layout loaders re-run against the freshly
|
|
240
|
+
// authenticated user — see the note in auth-login.tsx.
|
|
241
|
+
await router.push(redirect, { force: true });
|
|
242
|
+
} catch (err) {
|
|
243
|
+
setVerifyError(
|
|
244
|
+
err instanceof Error
|
|
245
|
+
? err.message
|
|
246
|
+
: tr("auth.register.verifyFailed", {
|
|
247
|
+
default: "Verification failed",
|
|
248
|
+
}),
|
|
249
|
+
);
|
|
250
|
+
} finally {
|
|
251
|
+
setSubmitting(false);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// Query appended to the "already have an account? sign in" link: the realm,
|
|
256
|
+
// plus the post-auth redirect (`?redirect=`) so signing in returns the user
|
|
257
|
+
// to wherever registering would have sent them (it's dropped otherwise).
|
|
258
|
+
const realmBit = props.realmConfig.realmName
|
|
259
|
+
? `realm=${encodeURIComponent(props.realmConfig.realmName)}`
|
|
260
|
+
: "";
|
|
261
|
+
const redirectBit =
|
|
262
|
+
typeof router.query.redirect === "string" && router.query.redirect
|
|
263
|
+
? `redirect=${encodeURIComponent(router.query.redirect)}`
|
|
264
|
+
: "";
|
|
265
|
+
const loginQ = [realmBit, redirectBit].filter(Boolean).join("&");
|
|
266
|
+
const realmQuery = loginQ ? `?${loginQ}` : "";
|
|
267
|
+
|
|
268
|
+
const externalMethods = props.realmConfig.authenticationMethods.filter(
|
|
269
|
+
(m) => m.type !== "CREDENTIALS",
|
|
270
|
+
);
|
|
271
|
+
const showDivider = credentialsProvider && externalMethods.length > 0;
|
|
272
|
+
const isVerifying = state.phase === "verification" && state.intent;
|
|
273
|
+
const canSubmitVerify =
|
|
274
|
+
!isVerifying ||
|
|
275
|
+
((!state.intent!.expectEmailVerification || emailCode.length === 6) &&
|
|
276
|
+
(!state.intent!.expectPhoneVerification || phoneCode.length === 6));
|
|
277
|
+
|
|
278
|
+
const contentRef = useRef<HTMLDivElement>(null);
|
|
279
|
+
const [contentHeight, setContentHeight] = useState<number | undefined>(
|
|
280
|
+
undefined,
|
|
281
|
+
);
|
|
282
|
+
useLayoutEffect(() => {
|
|
283
|
+
const el = contentRef.current;
|
|
284
|
+
if (!el) return;
|
|
285
|
+
setContentHeight(el.scrollHeight);
|
|
286
|
+
const ro = new ResizeObserver(() => {
|
|
287
|
+
setContentHeight(el.scrollHeight);
|
|
288
|
+
});
|
|
289
|
+
ro.observe(el);
|
|
290
|
+
return () => ro.disconnect();
|
|
291
|
+
}, []);
|
|
292
|
+
|
|
293
|
+
return (
|
|
294
|
+
<Centered>
|
|
295
|
+
{props.logo ?? (
|
|
296
|
+
<RealmLogo
|
|
297
|
+
settings={settings}
|
|
298
|
+
realmName={props.realmConfig.realmName}
|
|
299
|
+
/>
|
|
300
|
+
)}
|
|
301
|
+
<Card className="w-full">
|
|
302
|
+
<CardContent
|
|
303
|
+
className="overflow-hidden p-0 transition-[height] duration-300 ease-out"
|
|
304
|
+
style={
|
|
305
|
+
contentHeight !== undefined ? { height: contentHeight } : undefined
|
|
306
|
+
}
|
|
307
|
+
>
|
|
308
|
+
<div ref={contentRef}>
|
|
309
|
+
<div
|
|
310
|
+
key={state.phase}
|
|
311
|
+
className="animate-in fade-in duration-300 flex flex-col gap-4 px-6"
|
|
312
|
+
>
|
|
313
|
+
{isVerifying ? (
|
|
314
|
+
<>
|
|
315
|
+
<h2 className="text-center text-lg font-semibold">
|
|
316
|
+
{tr("auth.register.verifyTitle", {
|
|
317
|
+
default: "Verify your account",
|
|
318
|
+
})}
|
|
319
|
+
</h2>
|
|
320
|
+
<p className="text-muted-foreground text-center text-sm">
|
|
321
|
+
{tr("auth.register.verifyHint", {
|
|
322
|
+
default:
|
|
323
|
+
"Please enter the verification code(s) sent to you.",
|
|
324
|
+
})}
|
|
325
|
+
</p>
|
|
326
|
+
{verifyError && (
|
|
327
|
+
<Alert variant="destructive">
|
|
328
|
+
<AlertCircle className="size-4" />
|
|
329
|
+
<AlertDescription>{verifyError}</AlertDescription>
|
|
330
|
+
</Alert>
|
|
331
|
+
)}
|
|
332
|
+
{state.intent!.expectEmailVerification && (
|
|
333
|
+
<div className="flex flex-col items-center gap-2">
|
|
334
|
+
<Label htmlFor="emailCode">
|
|
335
|
+
{tr("auth.register.emailCode", {
|
|
336
|
+
default: "Email verification code",
|
|
337
|
+
})}
|
|
338
|
+
</Label>
|
|
339
|
+
<InputOTP
|
|
340
|
+
id="emailCode"
|
|
341
|
+
maxLength={6}
|
|
342
|
+
autoComplete="one-time-code"
|
|
343
|
+
autoFocus
|
|
344
|
+
value={emailCode}
|
|
345
|
+
onChange={setEmailCode}
|
|
346
|
+
>
|
|
347
|
+
<InputOTPGroup>
|
|
348
|
+
<InputOTPSlot index={0} />
|
|
349
|
+
<InputOTPSlot index={1} />
|
|
350
|
+
<InputOTPSlot index={2} />
|
|
351
|
+
</InputOTPGroup>
|
|
352
|
+
<InputOTPSeparator />
|
|
353
|
+
<InputOTPGroup>
|
|
354
|
+
<InputOTPSlot index={3} />
|
|
355
|
+
<InputOTPSlot index={4} />
|
|
356
|
+
<InputOTPSlot index={5} />
|
|
357
|
+
</InputOTPGroup>
|
|
358
|
+
</InputOTP>
|
|
359
|
+
</div>
|
|
360
|
+
)}
|
|
361
|
+
{state.intent!.expectPhoneVerification && (
|
|
362
|
+
<div className="flex flex-col items-center gap-2">
|
|
363
|
+
<Label htmlFor="phoneCode">
|
|
364
|
+
{tr("auth.register.phoneCode", {
|
|
365
|
+
default: "Phone verification code",
|
|
366
|
+
})}
|
|
367
|
+
</Label>
|
|
368
|
+
<InputOTP
|
|
369
|
+
id="phoneCode"
|
|
370
|
+
maxLength={6}
|
|
371
|
+
autoComplete="one-time-code"
|
|
372
|
+
autoFocus={!state.intent!.expectEmailVerification}
|
|
373
|
+
value={phoneCode}
|
|
374
|
+
onChange={setPhoneCode}
|
|
375
|
+
>
|
|
376
|
+
<InputOTPGroup>
|
|
377
|
+
<InputOTPSlot index={0} />
|
|
378
|
+
<InputOTPSlot index={1} />
|
|
379
|
+
<InputOTPSlot index={2} />
|
|
380
|
+
</InputOTPGroup>
|
|
381
|
+
<InputOTPSeparator />
|
|
382
|
+
<InputOTPGroup>
|
|
383
|
+
<InputOTPSlot index={3} />
|
|
384
|
+
<InputOTPSlot index={4} />
|
|
385
|
+
<InputOTPSlot index={5} />
|
|
386
|
+
</InputOTPGroup>
|
|
387
|
+
</InputOTP>
|
|
388
|
+
</div>
|
|
389
|
+
)}
|
|
390
|
+
<Button
|
|
391
|
+
onClick={handleVerify}
|
|
392
|
+
loading={submitting}
|
|
393
|
+
disabled={!canSubmitVerify}
|
|
394
|
+
>
|
|
395
|
+
{tr("auth.register.verifySubmit", {
|
|
396
|
+
default: "Complete registration",
|
|
397
|
+
})}
|
|
398
|
+
</Button>
|
|
399
|
+
<Button
|
|
400
|
+
variant="ghost"
|
|
401
|
+
onClick={() => setState({ phase: "form" })}
|
|
402
|
+
>
|
|
403
|
+
{tr("auth.register.verifyBack", {
|
|
404
|
+
default: "Back to registration",
|
|
405
|
+
})}
|
|
406
|
+
</Button>
|
|
407
|
+
</>
|
|
408
|
+
) : (
|
|
409
|
+
<FormPhase
|
|
410
|
+
allowed={allowed}
|
|
411
|
+
form={form}
|
|
412
|
+
formError={formError ?? queryError}
|
|
413
|
+
loading={formState.loading}
|
|
414
|
+
passwordValue={passwordValue}
|
|
415
|
+
settings={settings}
|
|
416
|
+
realmName={props.realmConfig.realmName}
|
|
417
|
+
credentialsProvider={credentialsProvider}
|
|
418
|
+
externalMethods={externalMethods}
|
|
419
|
+
showDivider={showDivider}
|
|
420
|
+
redirect={redirect}
|
|
421
|
+
loginPath={props.loginPath}
|
|
422
|
+
realmQuery={realmQuery}
|
|
423
|
+
auth={auth}
|
|
424
|
+
captchaSiteKey={captchaSiteKey}
|
|
425
|
+
captchaToken={captchaToken}
|
|
426
|
+
captchaRef={captchaRef}
|
|
427
|
+
onCaptchaToken={setCaptchaToken}
|
|
428
|
+
message={props.message}
|
|
429
|
+
/>
|
|
430
|
+
)}
|
|
431
|
+
</div>
|
|
432
|
+
</div>
|
|
433
|
+
</CardContent>
|
|
434
|
+
</Card>
|
|
435
|
+
{!isVerifying && (
|
|
436
|
+
<Button
|
|
437
|
+
variant="ghost"
|
|
438
|
+
nativeButton={false}
|
|
439
|
+
render={<a href={props.cancelPath ?? "/"} />}
|
|
440
|
+
>
|
|
441
|
+
{tr("auth.register.cancel", { default: "Cancel" })}
|
|
442
|
+
</Button>
|
|
443
|
+
)}
|
|
444
|
+
</Centered>
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function FormPhase(props: {
|
|
449
|
+
allowed: boolean;
|
|
450
|
+
form: ReturnType<typeof useForm>;
|
|
451
|
+
formError: string | undefined;
|
|
452
|
+
loading: boolean;
|
|
453
|
+
passwordValue: string;
|
|
454
|
+
settings: RealmConfig["settings"];
|
|
455
|
+
realmName: string;
|
|
456
|
+
credentialsProvider: any;
|
|
457
|
+
externalMethods: Array<{ name: string; type: string }>;
|
|
458
|
+
showDivider: boolean | undefined;
|
|
459
|
+
redirect: string;
|
|
460
|
+
loginPath: string | undefined;
|
|
461
|
+
realmQuery: string;
|
|
462
|
+
auth: ReturnType<typeof useAuth>;
|
|
463
|
+
captchaSiteKey?: string;
|
|
464
|
+
captchaToken?: string;
|
|
465
|
+
captchaRef: React.RefObject<TurnstileWidgetHandle | null>;
|
|
466
|
+
onCaptchaToken: (token: string | undefined) => void;
|
|
467
|
+
message?: ReactNode;
|
|
468
|
+
}) {
|
|
469
|
+
const { tr } = useI18n();
|
|
470
|
+
const [passwordFieldFocused, setPasswordFieldFocused] = useState(false);
|
|
471
|
+
const {
|
|
472
|
+
allowed,
|
|
473
|
+
form,
|
|
474
|
+
formError,
|
|
475
|
+
passwordValue,
|
|
476
|
+
settings,
|
|
477
|
+
credentialsProvider,
|
|
478
|
+
externalMethods,
|
|
479
|
+
showDivider,
|
|
480
|
+
redirect,
|
|
481
|
+
realmQuery,
|
|
482
|
+
} = props;
|
|
483
|
+
return (
|
|
484
|
+
<>
|
|
485
|
+
<RealmHeader settings={settings} realmName={props.realmName} />
|
|
486
|
+
{!allowed ? (
|
|
487
|
+
<>
|
|
488
|
+
<Alert>
|
|
489
|
+
<AlertCircle className="size-4" />
|
|
490
|
+
<AlertDescription>
|
|
491
|
+
{tr("auth.register.disabled", {
|
|
492
|
+
default:
|
|
493
|
+
"Registration is not available. Please contact your administrator.",
|
|
494
|
+
})}
|
|
495
|
+
</AlertDescription>
|
|
496
|
+
</Alert>
|
|
497
|
+
<Button
|
|
498
|
+
render={
|
|
499
|
+
<a href={`${props.loginPath ?? "/auth/login"}${realmQuery}`} />
|
|
500
|
+
}
|
|
501
|
+
>
|
|
502
|
+
{tr("auth.register.backToSignIn", { default: "Back to sign in" })}
|
|
503
|
+
</Button>
|
|
504
|
+
</>
|
|
505
|
+
) : (
|
|
506
|
+
<>
|
|
507
|
+
{props.message && (
|
|
508
|
+
<Alert>
|
|
509
|
+
<Info className="size-4" />
|
|
510
|
+
<AlertDescription>{props.message}</AlertDescription>
|
|
511
|
+
</Alert>
|
|
512
|
+
)}
|
|
513
|
+
{formError && (
|
|
514
|
+
<Alert variant="destructive">
|
|
515
|
+
<AlertCircle className="size-4" />
|
|
516
|
+
<AlertDescription>{formError}</AlertDescription>
|
|
517
|
+
</Alert>
|
|
518
|
+
)}
|
|
519
|
+
{credentialsProvider && (
|
|
520
|
+
<form {...form.props} className="flex flex-col gap-4">
|
|
521
|
+
{settings.firstNameLastName !== "none" &&
|
|
522
|
+
form.input.firstName &&
|
|
523
|
+
form.input.lastName && (
|
|
524
|
+
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
|
525
|
+
<Control
|
|
526
|
+
label={tr("auth.register.firstName", {
|
|
527
|
+
default: "First name",
|
|
528
|
+
})}
|
|
529
|
+
input={form.input.firstName}
|
|
530
|
+
autoComplete="given-name"
|
|
531
|
+
/>
|
|
532
|
+
<Control
|
|
533
|
+
label={tr("auth.register.lastName", {
|
|
534
|
+
default: "Last name",
|
|
535
|
+
})}
|
|
536
|
+
input={form.input.lastName}
|
|
537
|
+
autoComplete="family-name"
|
|
538
|
+
/>
|
|
539
|
+
</div>
|
|
540
|
+
)}
|
|
541
|
+
{settings.username !== "none" &&
|
|
542
|
+
settings.username !== "email" &&
|
|
543
|
+
form.input.username && (
|
|
544
|
+
<Control
|
|
545
|
+
label={tr("auth.register.username", {
|
|
546
|
+
default: "Username",
|
|
547
|
+
})}
|
|
548
|
+
input={form.input.username}
|
|
549
|
+
icon={iconFor("user")}
|
|
550
|
+
autoComplete="username"
|
|
551
|
+
/>
|
|
552
|
+
)}
|
|
553
|
+
{settings.email !== "none" && form.input.email && (
|
|
554
|
+
<Control
|
|
555
|
+
label={tr("auth.register.email", { default: "Email" })}
|
|
556
|
+
description={
|
|
557
|
+
settings.verifyEmailRequired
|
|
558
|
+
? tr("auth.register.email.verify", {
|
|
559
|
+
default:
|
|
560
|
+
"We'll send a verification code to confirm your email.",
|
|
561
|
+
})
|
|
562
|
+
: undefined
|
|
563
|
+
}
|
|
564
|
+
input={form.input.email}
|
|
565
|
+
icon={iconFor("email")}
|
|
566
|
+
/>
|
|
567
|
+
)}
|
|
568
|
+
{settings.phoneNumber !== "none" && form.input.phoneNumber && (
|
|
569
|
+
<Control
|
|
570
|
+
label={tr("auth.register.phone", {
|
|
571
|
+
default: "Phone number",
|
|
572
|
+
})}
|
|
573
|
+
description={
|
|
574
|
+
settings.verifyPhoneRequired
|
|
575
|
+
? tr("auth.register.phone.verify", {
|
|
576
|
+
default:
|
|
577
|
+
"We'll send a verification code to confirm your phone number.",
|
|
578
|
+
})
|
|
579
|
+
: undefined
|
|
580
|
+
}
|
|
581
|
+
input={form.input.phoneNumber}
|
|
582
|
+
icon={iconFor("phone")}
|
|
583
|
+
/>
|
|
584
|
+
)}
|
|
585
|
+
{/* `onFocus`/`onBlur` bubble from the input + toggle inside —
|
|
586
|
+
the rules stay visible while the user types or interacts
|
|
587
|
+
with the password toggle, and only collapse once the field
|
|
588
|
+
is blurred AND empty. */}
|
|
589
|
+
<div
|
|
590
|
+
onFocus={() => setPasswordFieldFocused(true)}
|
|
591
|
+
onBlur={() => setPasswordFieldFocused(false)}
|
|
592
|
+
>
|
|
593
|
+
<Control
|
|
594
|
+
label={tr("auth.register.password", { default: "Password" })}
|
|
595
|
+
input={form.input.password}
|
|
596
|
+
password
|
|
597
|
+
autoComplete="new-password"
|
|
598
|
+
/>
|
|
599
|
+
</div>
|
|
600
|
+
{(passwordFieldFocused || passwordValue.length > 0) && (
|
|
601
|
+
<PasswordRules
|
|
602
|
+
policy={settings.passwordPolicy}
|
|
603
|
+
value={passwordValue}
|
|
604
|
+
/>
|
|
605
|
+
)}
|
|
606
|
+
{props.captchaSiteKey && (
|
|
607
|
+
<TurnstileWidget
|
|
608
|
+
ref={props.captchaRef}
|
|
609
|
+
siteKey={props.captchaSiteKey}
|
|
610
|
+
onToken={props.onCaptchaToken}
|
|
611
|
+
className="flex justify-center"
|
|
612
|
+
/>
|
|
613
|
+
)}
|
|
614
|
+
<Button
|
|
615
|
+
type="submit"
|
|
616
|
+
loading={props.loading}
|
|
617
|
+
disabled={!!props.captchaSiteKey && !props.captchaToken}
|
|
618
|
+
>
|
|
619
|
+
{tr("auth.register.submit", { default: "Create account" })}
|
|
620
|
+
</Button>
|
|
621
|
+
</form>
|
|
622
|
+
)}
|
|
623
|
+
{showDivider && (
|
|
624
|
+
<div className="flex items-center gap-3">
|
|
625
|
+
<Separator className="flex-1" />
|
|
626
|
+
<span className="text-muted-foreground text-xs">
|
|
627
|
+
{tr("auth.register.or", { default: "OR" })}
|
|
628
|
+
</span>
|
|
629
|
+
<Separator className="flex-1" />
|
|
630
|
+
</div>
|
|
631
|
+
)}
|
|
632
|
+
{externalMethods.map((method) => {
|
|
633
|
+
const provider =
|
|
634
|
+
method.name.charAt(0).toUpperCase() + method.name.slice(1);
|
|
635
|
+
return (
|
|
636
|
+
<Button
|
|
637
|
+
key={method.name}
|
|
638
|
+
variant="outline"
|
|
639
|
+
onClick={() =>
|
|
640
|
+
props.auth.login(method.name as never, {
|
|
641
|
+
redirect,
|
|
642
|
+
realm: props.realmName,
|
|
643
|
+
})
|
|
644
|
+
}
|
|
645
|
+
>
|
|
646
|
+
<BrandIcon provider={method.name} />
|
|
647
|
+
{tr("auth.register.continueWith", {
|
|
648
|
+
default: `Continue with ${provider}`,
|
|
649
|
+
args: [provider],
|
|
650
|
+
})}
|
|
651
|
+
</Button>
|
|
652
|
+
);
|
|
653
|
+
})}
|
|
654
|
+
<p className="text-muted-foreground text-center text-sm">
|
|
655
|
+
{tr("auth.register.haveAccount", {
|
|
656
|
+
default: "Already have an account?",
|
|
657
|
+
})}{" "}
|
|
658
|
+
<a
|
|
659
|
+
href={`${props.loginPath ?? "/auth/login"}${realmQuery}`}
|
|
660
|
+
className="text-foreground underline-offset-4 hover:underline"
|
|
661
|
+
>
|
|
662
|
+
{tr("auth.register.signIn", { default: "Sign in" })}
|
|
663
|
+
</a>
|
|
664
|
+
</p>
|
|
665
|
+
</>
|
|
666
|
+
)}
|
|
667
|
+
</>
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
function Centered(props: { children: React.ReactNode }) {
|
|
672
|
+
return (
|
|
673
|
+
<div className="flex min-h-svh flex-1 items-center justify-center p-6">
|
|
674
|
+
<div className="flex w-full max-w-sm flex-col items-center gap-4">
|
|
675
|
+
{props.children}
|
|
676
|
+
</div>
|
|
677
|
+
</div>
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
function RealmHeader(props: {
|
|
682
|
+
settings: RealmConfig["settings"];
|
|
683
|
+
realmName: string;
|
|
684
|
+
}) {
|
|
685
|
+
const s = props.settings;
|
|
686
|
+
if (!s.displayName && !s.description) return null;
|
|
687
|
+
return (
|
|
688
|
+
<div className="flex flex-col items-center gap-1">
|
|
689
|
+
{s.displayName && (
|
|
690
|
+
<h2 className="text-center text-lg font-semibold">{s.displayName}</h2>
|
|
691
|
+
)}
|
|
692
|
+
{s.description && (
|
|
693
|
+
<p className="text-muted-foreground text-center text-sm">
|
|
694
|
+
{s.description}
|
|
695
|
+
</p>
|
|
696
|
+
)}
|
|
697
|
+
</div>
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
function PasswordRules(props: {
|
|
702
|
+
policy: RealmConfig["settings"]["passwordPolicy"];
|
|
703
|
+
value: string;
|
|
704
|
+
}) {
|
|
705
|
+
const { tr } = useI18n();
|
|
706
|
+
const policy = props.policy;
|
|
707
|
+
const value = props.value;
|
|
708
|
+
|
|
709
|
+
const rules: { ok: boolean; label: string }[] = [];
|
|
710
|
+
|
|
711
|
+
if (policy?.minLength && policy.minLength > 0) {
|
|
712
|
+
rules.push({
|
|
713
|
+
ok: value.length >= policy.minLength,
|
|
714
|
+
label: tr("auth.register.password.rule.minLength", {
|
|
715
|
+
default: `At least ${policy.minLength} characters`,
|
|
716
|
+
args: [String(policy.minLength)],
|
|
717
|
+
}),
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
if (policy?.requireUppercase) {
|
|
721
|
+
rules.push({
|
|
722
|
+
ok: /[A-Z]/.test(value),
|
|
723
|
+
label: tr("auth.register.password.rule.uppercase", {
|
|
724
|
+
default: "One uppercase letter",
|
|
725
|
+
}),
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
if (policy?.requireLowercase) {
|
|
729
|
+
rules.push({
|
|
730
|
+
ok: /[a-z]/.test(value),
|
|
731
|
+
label: tr("auth.register.password.rule.lowercase", {
|
|
732
|
+
default: "One lowercase letter",
|
|
733
|
+
}),
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
if (policy?.requireNumbers) {
|
|
737
|
+
rules.push({
|
|
738
|
+
ok: /[0-9]/.test(value),
|
|
739
|
+
label: tr("auth.register.password.rule.number", {
|
|
740
|
+
default: "One number",
|
|
741
|
+
}),
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
if (policy?.requireSpecialCharacters) {
|
|
745
|
+
rules.push({
|
|
746
|
+
ok: /[^A-Za-z0-9]/.test(value),
|
|
747
|
+
label: tr("auth.register.password.rule.special", {
|
|
748
|
+
default: "One special character",
|
|
749
|
+
}),
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
if (rules.length === 0) return null;
|
|
754
|
+
|
|
755
|
+
return (
|
|
756
|
+
<ul className="text-muted-foreground -mt-2 flex flex-col gap-1 text-xs">
|
|
757
|
+
{rules.map((rule, idx) => (
|
|
758
|
+
<li
|
|
759
|
+
key={idx}
|
|
760
|
+
className={`flex items-center gap-1.5 ${rule.ok ? "text-emerald-600 dark:text-emerald-400" : ""}`}
|
|
761
|
+
>
|
|
762
|
+
{rule.ok ? (
|
|
763
|
+
<Check className="size-3.5" />
|
|
764
|
+
) : (
|
|
765
|
+
<X className="size-3.5 opacity-50" />
|
|
766
|
+
)}
|
|
767
|
+
<span>{rule.label}</span>
|
|
768
|
+
</li>
|
|
769
|
+
))}
|
|
770
|
+
</ul>
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
function RealmLogo(props: {
|
|
775
|
+
settings: RealmConfig["settings"];
|
|
776
|
+
realmName: string;
|
|
777
|
+
}) {
|
|
778
|
+
if (!props.settings.logoUrl) return null;
|
|
779
|
+
return (
|
|
780
|
+
<img
|
|
781
|
+
src={props.settings.logoUrl}
|
|
782
|
+
alt={props.settings.displayName || props.realmName}
|
|
783
|
+
className="size-16 rounded-xl border bg-muted object-cover shadow-sm"
|
|
784
|
+
/>
|
|
785
|
+
);
|
|
786
|
+
}
|