@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,349 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import { Control } from "@alepha/ui/components/control/control";
|
|
6
|
+
import { iconFor } from "@alepha/ui/components/control-base/icon-hint";
|
|
7
|
+
import { Alert, AlertDescription } from "@alepha/ui/components/ui/alert";
|
|
8
|
+
import { Button } from "@alepha/ui/components/ui/button";
|
|
9
|
+
import { Card, CardContent } from "@alepha/ui/components/ui/card";
|
|
10
|
+
import {
|
|
11
|
+
InputOTP,
|
|
12
|
+
InputOTPGroup,
|
|
13
|
+
InputOTPSlot,
|
|
14
|
+
} from "@alepha/ui/components/ui/input-otp";
|
|
15
|
+
import { Label } from "@alepha/ui/components/ui/label";
|
|
16
|
+
import { AlephaError, z } from "alepha";
|
|
17
|
+
import type {
|
|
18
|
+
PasswordResetIntentResponse,
|
|
19
|
+
RealmConfig,
|
|
20
|
+
UserController,
|
|
21
|
+
} from "alepha/api/users";
|
|
22
|
+
import { resetPasswordRequestSchema } from "alepha/api/users";
|
|
23
|
+
import { useClient } from "alepha/react";
|
|
24
|
+
import { useForm, useFormState } from "alepha/react/form";
|
|
25
|
+
import { useI18n } from "alepha/react/i18n";
|
|
26
|
+
import { useRouter } from "alepha/react/router";
|
|
27
|
+
import { AlertCircle, CheckCircle2, Info } from "lucide-react";
|
|
28
|
+
import { type ReactNode, useState } from "react";
|
|
29
|
+
|
|
30
|
+
export interface AuthResetPasswordProps {
|
|
31
|
+
/**
|
|
32
|
+
* Realm configuration (controls verification channel and password rules).
|
|
33
|
+
*/
|
|
34
|
+
realmConfig: RealmConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Route to the login page, used after a successful reset.
|
|
37
|
+
*/
|
|
38
|
+
loginPath?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Custom logo node, rendered above the form. When provided, it replaces
|
|
41
|
+
* the default `settings.logoUrl` <img>. Use this to inject a branded
|
|
42
|
+
* component (e.g. with light/dark variants or an animation).
|
|
43
|
+
*/
|
|
44
|
+
logo?: ReactNode;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type Step = "email" | "code" | "password" | "success";
|
|
48
|
+
|
|
49
|
+
interface State {
|
|
50
|
+
step: Step;
|
|
51
|
+
intent?: PasswordResetIntentResponse;
|
|
52
|
+
email?: string;
|
|
53
|
+
code?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function AuthResetPassword(props: AuthResetPasswordProps) {
|
|
57
|
+
const router = useRouter();
|
|
58
|
+
const { tr } = useI18n();
|
|
59
|
+
const userCtrl = useClient<UserController>();
|
|
60
|
+
const [state, setState] = useState<State>({ step: "email" });
|
|
61
|
+
const [error, setError] = useState<string | null>(null);
|
|
62
|
+
const [submitting, setSubmitting] = useState(false);
|
|
63
|
+
const [code, setCode] = useState("");
|
|
64
|
+
const redirect = router.query.redirect || "/";
|
|
65
|
+
|
|
66
|
+
const settings = props.realmConfig.settings;
|
|
67
|
+
const allowed = settings?.resetPasswordAllowed !== false;
|
|
68
|
+
// Keep BOTH realm and the post-auth redirect on the "back to sign in"
|
|
69
|
+
// links so a reset started mid-flow (OIDC continuation) resumes after
|
|
70
|
+
// login. Mirrors auth-login / auth-register.
|
|
71
|
+
const realmBit = props.realmConfig.realmName
|
|
72
|
+
? `realm=${encodeURIComponent(props.realmConfig.realmName)}`
|
|
73
|
+
: "";
|
|
74
|
+
const redirectBit =
|
|
75
|
+
typeof router.query.redirect === "string" && router.query.redirect
|
|
76
|
+
? `redirect=${encodeURIComponent(router.query.redirect)}`
|
|
77
|
+
: "";
|
|
78
|
+
const linkQ = [realmBit, redirectBit].filter(Boolean).join("&");
|
|
79
|
+
const realmQuery = linkQ ? `?${linkQ}` : "";
|
|
80
|
+
|
|
81
|
+
const emailForm = useForm({
|
|
82
|
+
schema: resetPasswordRequestSchema,
|
|
83
|
+
handler: async (data) => {
|
|
84
|
+
setError(null);
|
|
85
|
+
const intent = await userCtrl.createPasswordResetIntent({
|
|
86
|
+
query: { userRealmName: props.realmConfig.realmName },
|
|
87
|
+
body: { email: data.email },
|
|
88
|
+
});
|
|
89
|
+
setState({ step: "code", intent, email: data.email });
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const passwordForm = useForm(
|
|
94
|
+
{
|
|
95
|
+
schema: z.object({
|
|
96
|
+
password: z.string().min(8),
|
|
97
|
+
confirmPassword: z.string().min(8),
|
|
98
|
+
}),
|
|
99
|
+
handler: async (data) => {
|
|
100
|
+
if (data.password !== data.confirmPassword) {
|
|
101
|
+
throw new AlephaError(
|
|
102
|
+
tr("auth.reset.passwordsMismatch", {
|
|
103
|
+
default: "Passwords do not match",
|
|
104
|
+
}),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
if (!state.intent || !state.code) {
|
|
108
|
+
throw new AlephaError(
|
|
109
|
+
tr("auth.reset.invalidState", { default: "Invalid reset state" }),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
await userCtrl.completePasswordReset({
|
|
113
|
+
body: {
|
|
114
|
+
intentId: state.intent.intentId,
|
|
115
|
+
code: state.code,
|
|
116
|
+
newPassword: data.password,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
setState({ step: "success" });
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
[state.intent, state.code],
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const { loading: emailSubmitting } = useFormState(emailForm, ["loading"]);
|
|
126
|
+
const { loading: passwordSubmitting } = useFormState(passwordForm, [
|
|
127
|
+
"loading",
|
|
128
|
+
]);
|
|
129
|
+
|
|
130
|
+
const handleCodeSubmit = () => {
|
|
131
|
+
if (code.length === 6) {
|
|
132
|
+
setState((s) => ({ ...s, step: "password", code }));
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const handleResend = async () => {
|
|
137
|
+
if (!state.email) return;
|
|
138
|
+
setSubmitting(true);
|
|
139
|
+
setError(null);
|
|
140
|
+
try {
|
|
141
|
+
const intent = await userCtrl.createPasswordResetIntent({
|
|
142
|
+
query: { userRealmName: props.realmConfig.realmName },
|
|
143
|
+
body: { email: state.email },
|
|
144
|
+
});
|
|
145
|
+
setState((s) => ({ ...s, intent }));
|
|
146
|
+
} catch (e) {
|
|
147
|
+
setError(
|
|
148
|
+
e instanceof Error
|
|
149
|
+
? e.message
|
|
150
|
+
: tr("auth.reset.resendFailed", {
|
|
151
|
+
default: "Failed to resend code",
|
|
152
|
+
}),
|
|
153
|
+
);
|
|
154
|
+
} finally {
|
|
155
|
+
setSubmitting(false);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<div className="flex min-h-svh flex-1 items-center justify-center p-6">
|
|
161
|
+
<div className="flex w-full max-w-sm flex-col items-center gap-4">
|
|
162
|
+
{props.logo ??
|
|
163
|
+
(settings?.logoUrl ? (
|
|
164
|
+
<img
|
|
165
|
+
src={settings.logoUrl}
|
|
166
|
+
alt={settings.displayName || props.realmConfig.realmName}
|
|
167
|
+
className="size-16 rounded-xl border bg-muted object-cover shadow-sm"
|
|
168
|
+
/>
|
|
169
|
+
) : null)}
|
|
170
|
+
<Card className="w-full">
|
|
171
|
+
<CardContent className="flex flex-col gap-4">
|
|
172
|
+
{error && (
|
|
173
|
+
<Alert variant="destructive">
|
|
174
|
+
<AlertCircle className="size-4" />
|
|
175
|
+
<AlertDescription>{error}</AlertDescription>
|
|
176
|
+
</Alert>
|
|
177
|
+
)}
|
|
178
|
+
{!allowed ? (
|
|
179
|
+
<>
|
|
180
|
+
<Alert>
|
|
181
|
+
<AlertCircle className="size-4" />
|
|
182
|
+
<AlertDescription>
|
|
183
|
+
{tr("auth.reset.disabled", {
|
|
184
|
+
default:
|
|
185
|
+
"Password reset is not available. Please contact your administrator.",
|
|
186
|
+
})}
|
|
187
|
+
</AlertDescription>
|
|
188
|
+
</Alert>
|
|
189
|
+
<Button
|
|
190
|
+
render={
|
|
191
|
+
<a
|
|
192
|
+
href={`${props.loginPath ?? "/auth/login"}${realmQuery}`}
|
|
193
|
+
/>
|
|
194
|
+
}
|
|
195
|
+
>
|
|
196
|
+
{tr("auth.reset.backToSignIn", {
|
|
197
|
+
default: "Back to sign in",
|
|
198
|
+
})}
|
|
199
|
+
</Button>
|
|
200
|
+
</>
|
|
201
|
+
) : state.step === "email" ? (
|
|
202
|
+
<form {...emailForm.props} className="flex flex-col gap-4">
|
|
203
|
+
<h2 className="text-center text-lg font-semibold">
|
|
204
|
+
{tr("auth.reset.title", { default: "Reset password" })}
|
|
205
|
+
</h2>
|
|
206
|
+
<p className="text-muted-foreground text-sm">
|
|
207
|
+
{tr("auth.reset.emailHint", {
|
|
208
|
+
default: "Enter your email address to reset your password",
|
|
209
|
+
})}
|
|
210
|
+
</p>
|
|
211
|
+
<Control
|
|
212
|
+
label={tr("auth.reset.email", { default: "Email" })}
|
|
213
|
+
input={emailForm.input.email}
|
|
214
|
+
icon={iconFor("email")}
|
|
215
|
+
/>
|
|
216
|
+
<Button type="submit" loading={emailSubmitting}>
|
|
217
|
+
{tr("auth.reset.sendCode", {
|
|
218
|
+
default: "Send verification code",
|
|
219
|
+
})}
|
|
220
|
+
</Button>
|
|
221
|
+
</form>
|
|
222
|
+
) : state.step === "code" ? (
|
|
223
|
+
<div className="flex flex-col gap-4">
|
|
224
|
+
<h2 className="text-center text-lg font-semibold">
|
|
225
|
+
{tr("auth.reset.title", { default: "Reset password" })}
|
|
226
|
+
</h2>
|
|
227
|
+
<Alert>
|
|
228
|
+
<Info className="size-4" />
|
|
229
|
+
<AlertDescription>
|
|
230
|
+
{tr("auth.reset.codeSent", {
|
|
231
|
+
default: "We've sent a verification code to your email.",
|
|
232
|
+
})}
|
|
233
|
+
</AlertDescription>
|
|
234
|
+
</Alert>
|
|
235
|
+
<div className="flex flex-col items-center gap-2">
|
|
236
|
+
<Label htmlFor="code">
|
|
237
|
+
{tr("auth.reset.codeLabel", {
|
|
238
|
+
default: "Enter the 6-digit code",
|
|
239
|
+
})}
|
|
240
|
+
</Label>
|
|
241
|
+
<InputOTP
|
|
242
|
+
id="code"
|
|
243
|
+
maxLength={6}
|
|
244
|
+
autoFocus
|
|
245
|
+
value={code}
|
|
246
|
+
onChange={(value) => setCode(value.replace(/\D/g, ""))}
|
|
247
|
+
>
|
|
248
|
+
<InputOTPGroup>
|
|
249
|
+
<InputOTPSlot index={0} />
|
|
250
|
+
<InputOTPSlot index={1} />
|
|
251
|
+
<InputOTPSlot index={2} />
|
|
252
|
+
<InputOTPSlot index={3} />
|
|
253
|
+
<InputOTPSlot index={4} />
|
|
254
|
+
<InputOTPSlot index={5} />
|
|
255
|
+
</InputOTPGroup>
|
|
256
|
+
</InputOTP>
|
|
257
|
+
</div>
|
|
258
|
+
<Button onClick={handleCodeSubmit} disabled={code.length !== 6}>
|
|
259
|
+
{tr("auth.reset.continue", { default: "Continue" })}
|
|
260
|
+
</Button>
|
|
261
|
+
<Button
|
|
262
|
+
variant="ghost"
|
|
263
|
+
onClick={handleResend}
|
|
264
|
+
loading={submitting}
|
|
265
|
+
>
|
|
266
|
+
{tr("auth.reset.resend", { default: "Resend code" })}
|
|
267
|
+
</Button>
|
|
268
|
+
</div>
|
|
269
|
+
) : state.step === "password" ? (
|
|
270
|
+
<form {...passwordForm.props} className="flex flex-col gap-4">
|
|
271
|
+
{/* Hidden identifier so password managers know which saved
|
|
272
|
+
credential the new password belongs to. Without it,
|
|
273
|
+
Safari/Chrome won't offer to update the existing entry. */}
|
|
274
|
+
{state.email && (
|
|
275
|
+
<input
|
|
276
|
+
type="text"
|
|
277
|
+
name="username"
|
|
278
|
+
autoComplete="username"
|
|
279
|
+
value={state.email}
|
|
280
|
+
readOnly
|
|
281
|
+
hidden
|
|
282
|
+
/>
|
|
283
|
+
)}
|
|
284
|
+
<h2 className="text-center text-lg font-semibold">
|
|
285
|
+
{tr("auth.reset.title", { default: "Reset password" })}
|
|
286
|
+
</h2>
|
|
287
|
+
<p className="text-muted-foreground text-sm">
|
|
288
|
+
{tr("auth.reset.newPasswordHint", {
|
|
289
|
+
default: "Create your new password",
|
|
290
|
+
})}
|
|
291
|
+
</p>
|
|
292
|
+
<Control
|
|
293
|
+
label={tr("auth.reset.newPassword", {
|
|
294
|
+
default: "New password",
|
|
295
|
+
})}
|
|
296
|
+
input={passwordForm.input.password}
|
|
297
|
+
password
|
|
298
|
+
autoComplete="new-password"
|
|
299
|
+
/>
|
|
300
|
+
<Control
|
|
301
|
+
label={tr("auth.reset.confirmPassword", {
|
|
302
|
+
default: "Confirm password",
|
|
303
|
+
})}
|
|
304
|
+
input={passwordForm.input.confirmPassword}
|
|
305
|
+
password
|
|
306
|
+
autoComplete="new-password"
|
|
307
|
+
/>
|
|
308
|
+
<Button type="submit" loading={passwordSubmitting}>
|
|
309
|
+
{tr("auth.reset.setPassword", {
|
|
310
|
+
default: "Set new password",
|
|
311
|
+
})}
|
|
312
|
+
</Button>
|
|
313
|
+
</form>
|
|
314
|
+
) : (
|
|
315
|
+
<>
|
|
316
|
+
<Alert>
|
|
317
|
+
<CheckCircle2 className="size-4" />
|
|
318
|
+
<AlertDescription>
|
|
319
|
+
{tr("auth.reset.success", {
|
|
320
|
+
default: "Your password has been reset successfully.",
|
|
321
|
+
})}
|
|
322
|
+
</AlertDescription>
|
|
323
|
+
</Alert>
|
|
324
|
+
<Button
|
|
325
|
+
render={
|
|
326
|
+
<a
|
|
327
|
+
href={`${props.loginPath ?? "/auth/login"}${realmQuery}`}
|
|
328
|
+
/>
|
|
329
|
+
}
|
|
330
|
+
>
|
|
331
|
+
{tr("auth.reset.backToSignIn", {
|
|
332
|
+
default: "Back to sign in",
|
|
333
|
+
})}
|
|
334
|
+
</Button>
|
|
335
|
+
</>
|
|
336
|
+
)}
|
|
337
|
+
</CardContent>
|
|
338
|
+
</Card>
|
|
339
|
+
<Button
|
|
340
|
+
variant="ghost"
|
|
341
|
+
nativeButton={false}
|
|
342
|
+
render={<a href={redirect} />}
|
|
343
|
+
>
|
|
344
|
+
{tr("auth.reset.cancel", { default: "Cancel" })}
|
|
345
|
+
</Button>
|
|
346
|
+
</div>
|
|
347
|
+
</div>
|
|
348
|
+
);
|
|
349
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { RealmController } from "alepha/api/users";
|
|
2
|
+
import { $page } from "alepha/react/router";
|
|
3
|
+
import { $client } from "alepha/server/links";
|
|
4
|
+
import { AuthLogin } from "./auth-login.tsx";
|
|
5
|
+
import { AuthRegister } from "./auth-register.tsx";
|
|
6
|
+
import { AuthResetPassword } from "./auth-reset-password.tsx";
|
|
7
|
+
import { AuthVerifyEmail } from "./auth-verify-email.tsx";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The four authentication screens, mounted and wired — a router you can use
|
|
11
|
+
* as-is.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { AuthRouter } from "@alepha/ui/components/auth/auth-router";
|
|
15
|
+
*
|
|
16
|
+
* export const MyWeb = $module({
|
|
17
|
+
* name: "my.web",
|
|
18
|
+
* services: [MyRouter, AuthRouter],
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* That is the whole integration: `/auth/login`, `/auth/register`,
|
|
23
|
+
* `/auth/reset-password` and `/auth/verify-email` exist, each loads the realm
|
|
24
|
+
* configuration, and the links between them point at each other.
|
|
25
|
+
*
|
|
26
|
+
* ### Why this exists
|
|
27
|
+
*
|
|
28
|
+
* `@alepha/mantine/auth/AuthRouter` used to do exactly this, and was deleted with
|
|
29
|
+
* Mantine without being ported. What survived were the components — the bricks
|
|
30
|
+
* without the thing that assembled them — so every application rebuilt the same
|
|
31
|
+
* four pages by hand: `apps/lore` in 414 lines across two files, `apps/shop` in
|
|
32
|
+
* three more. `apps/shop` has since been moved onto this router and deleted its
|
|
33
|
+
* three; `apps/lore` still has its own.
|
|
34
|
+
*
|
|
35
|
+
* Worse, the components kept the old router's paths as their fallbacks
|
|
36
|
+
* (`props.loginPath ?? "/auth/login"`). Those defaults described a topology
|
|
37
|
+
* nothing mounted any more, so an application that placed its pages elsewhere
|
|
38
|
+
* inherited internal links pointing at nothing — a 404 you only find by clicking,
|
|
39
|
+
* invisible to typecheck, to tests, and to an e2e suite that reaches the sign-in
|
|
40
|
+
* page by URL. Mounting this router makes those defaults true again.
|
|
41
|
+
*
|
|
42
|
+
* ### Optional, and replaceable
|
|
43
|
+
*
|
|
44
|
+
* Nothing imports it implicitly. An application that wants different URLs — say
|
|
45
|
+
* `/compte/connexion` for a French storefront — writes its own router and passes
|
|
46
|
+
* the components' path props itself; that stays entirely supported, and this
|
|
47
|
+
* class is a readable reference for what wiring it by hand involves. It is a real
|
|
48
|
+
* trade rather than a free one: `apps/shop` made exactly that choice, then gave
|
|
49
|
+
* it up for this router, because the French URLs also cost it a bespoke auth
|
|
50
|
+
* layout, four hand-kept cross-links and the `verify-email` page it never got
|
|
51
|
+
* round to writing.
|
|
52
|
+
*
|
|
53
|
+
* The paths here are fixed on purpose. Making them configurable would mean
|
|
54
|
+
* threading a configuration object through four pages to save an application that
|
|
55
|
+
* wants its own URLs about twenty lines — and that application also wants its own
|
|
56
|
+
* titles, its own layout and its own copy. The seam is "use this router, or write
|
|
57
|
+
* one", not "use this router with a hundred options".
|
|
58
|
+
*/
|
|
59
|
+
export class AuthRouter {
|
|
60
|
+
protected readonly realmApi = $client<RealmController>();
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Shared by all four pages: every screen needs to know what the realm allows
|
|
64
|
+
* before it can decide what to render.
|
|
65
|
+
*/
|
|
66
|
+
protected loadRealm = async () => ({
|
|
67
|
+
realmConfig: await this.realmApi.getRealmConfig(),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Named `login` rather than `authLogin`, because that is the name other parts
|
|
72
|
+
* of the framework look for — `$secure`'s redirect and `ButtonUser`'s sign-in
|
|
73
|
+
* action both push a route called `login`.
|
|
74
|
+
*/
|
|
75
|
+
login = $page({
|
|
76
|
+
path: "/auth/login",
|
|
77
|
+
name: "login",
|
|
78
|
+
head: { title: "Sign in" },
|
|
79
|
+
loader: () => this.loadRealm(),
|
|
80
|
+
component: (props: { realmConfig: any }) => (
|
|
81
|
+
<AuthLogin
|
|
82
|
+
realmConfig={props.realmConfig}
|
|
83
|
+
registerPath="/auth/register"
|
|
84
|
+
resetPasswordPath="/auth/reset-password"
|
|
85
|
+
/>
|
|
86
|
+
),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
register = $page({
|
|
90
|
+
path: "/auth/register",
|
|
91
|
+
name: "register",
|
|
92
|
+
head: { title: "Create an account" },
|
|
93
|
+
loader: () => this.loadRealm(),
|
|
94
|
+
component: (props: { realmConfig: any }) => (
|
|
95
|
+
<AuthRegister
|
|
96
|
+
realmConfig={props.realmConfig}
|
|
97
|
+
loginPath="/auth/login"
|
|
98
|
+
cancelPath="/"
|
|
99
|
+
/>
|
|
100
|
+
),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
resetPassword = $page({
|
|
104
|
+
path: "/auth/reset-password",
|
|
105
|
+
name: "resetPassword",
|
|
106
|
+
head: { title: "Reset your password" },
|
|
107
|
+
loader: () => this.loadRealm(),
|
|
108
|
+
component: (props: { realmConfig: any }) => (
|
|
109
|
+
<AuthResetPassword
|
|
110
|
+
realmConfig={props.realmConfig}
|
|
111
|
+
loginPath="/auth/login"
|
|
112
|
+
/>
|
|
113
|
+
),
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Reached from a link in an email, so it takes its `email` and `token` from the
|
|
118
|
+
* query string rather than from any state the browser already holds.
|
|
119
|
+
*/
|
|
120
|
+
verifyEmail = $page({
|
|
121
|
+
path: "/auth/verify-email",
|
|
122
|
+
name: "verifyEmail",
|
|
123
|
+
head: { title: "Verify your email" },
|
|
124
|
+
component: () => <AuthVerifyEmail loginPath="/auth/login" />,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import { Alert, AlertDescription } from "@alepha/ui/components/ui/alert";
|
|
6
|
+
import { Button } from "@alepha/ui/components/ui/button";
|
|
7
|
+
import { Card, CardContent } from "@alepha/ui/components/ui/card";
|
|
8
|
+
import type { UserController } from "alepha/api/users";
|
|
9
|
+
import { useClient } from "alepha/react";
|
|
10
|
+
import { useI18n } from "alepha/react/i18n";
|
|
11
|
+
import { useRouterState } from "alepha/react/router";
|
|
12
|
+
import { AlertCircle, CheckCircle2, Loader2, MailCheck } from "lucide-react";
|
|
13
|
+
import { type ReactNode, useEffect, useState } from "react";
|
|
14
|
+
|
|
15
|
+
export type VerifyEmailStep = "verifying" | "success" | "error";
|
|
16
|
+
|
|
17
|
+
export interface AuthVerifyEmailProps {
|
|
18
|
+
/**
|
|
19
|
+
* Route to the login page, shown as a CTA on success/failure.
|
|
20
|
+
*/
|
|
21
|
+
loginPath?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Render a fixed step (useful for storybook / testing).
|
|
24
|
+
*/
|
|
25
|
+
step?: VerifyEmailStep;
|
|
26
|
+
/**
|
|
27
|
+
* Custom logo node, rendered above the card.
|
|
28
|
+
*/
|
|
29
|
+
logo?: ReactNode;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function AuthVerifyEmail(props: AuthVerifyEmailProps) {
|
|
33
|
+
if (props.step) {
|
|
34
|
+
return (
|
|
35
|
+
<View step={props.step} loginPath={props.loginPath} logo={props.logo} />
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return <Stateful loginPath={props.loginPath} logo={props.logo} />;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function Stateful(props: { loginPath?: string; logo?: ReactNode }) {
|
|
42
|
+
const state = useRouterState();
|
|
43
|
+
const { tr } = useI18n();
|
|
44
|
+
const userCtrl = useClient<UserController>();
|
|
45
|
+
const [step, setStep] = useState<VerifyEmailStep>("verifying");
|
|
46
|
+
const [error, setError] = useState<string | null>(null);
|
|
47
|
+
|
|
48
|
+
const email = state.query.email as string | undefined;
|
|
49
|
+
const token = state.query.token as string | undefined;
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const verify = async () => {
|
|
53
|
+
if (!email || !token) {
|
|
54
|
+
setError(
|
|
55
|
+
tr("auth.verify.invalidLink", {
|
|
56
|
+
default: "Invalid verification link. Email and token are required.",
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
59
|
+
setStep("error");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
await userCtrl.verifyEmail({ body: { email, token } });
|
|
64
|
+
setStep("success");
|
|
65
|
+
} catch (err) {
|
|
66
|
+
setError(
|
|
67
|
+
err instanceof Error
|
|
68
|
+
? err.message
|
|
69
|
+
: tr("auth.verify.failed", {
|
|
70
|
+
default:
|
|
71
|
+
"Failed to verify your email. The link may have expired or is invalid.",
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
setStep("error");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
void verify();
|
|
78
|
+
}, [email, token, userCtrl, tr]);
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<View
|
|
82
|
+
step={step}
|
|
83
|
+
error={error}
|
|
84
|
+
loginPath={props.loginPath}
|
|
85
|
+
logo={props.logo}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function View(props: {
|
|
91
|
+
step: VerifyEmailStep;
|
|
92
|
+
error?: string | null;
|
|
93
|
+
loginPath?: string;
|
|
94
|
+
logo?: ReactNode;
|
|
95
|
+
}) {
|
|
96
|
+
const { tr } = useI18n();
|
|
97
|
+
return (
|
|
98
|
+
<div className="flex min-h-svh flex-1 items-center justify-center p-6">
|
|
99
|
+
<div className="flex w-full max-w-sm flex-col items-center gap-4">
|
|
100
|
+
{props.logo}
|
|
101
|
+
<Card className="w-full">
|
|
102
|
+
<CardContent className="flex flex-col items-center gap-4">
|
|
103
|
+
{props.step === "verifying" && (
|
|
104
|
+
<>
|
|
105
|
+
<Loader2 className="text-muted-foreground size-12 animate-spin" />
|
|
106
|
+
<h2 className="text-center text-lg font-semibold">
|
|
107
|
+
{tr("auth.verify.verifying", {
|
|
108
|
+
default: "Verifying your email...",
|
|
109
|
+
})}
|
|
110
|
+
</h2>
|
|
111
|
+
<p className="text-muted-foreground text-center text-sm">
|
|
112
|
+
{tr("auth.verify.verifyingHint", {
|
|
113
|
+
default: "Please wait while we verify your email address.",
|
|
114
|
+
})}
|
|
115
|
+
</p>
|
|
116
|
+
</>
|
|
117
|
+
)}
|
|
118
|
+
{props.step === "success" && (
|
|
119
|
+
<>
|
|
120
|
+
<MailCheck className="size-12 text-green-600" />
|
|
121
|
+
<h2 className="text-center text-lg font-semibold">
|
|
122
|
+
{tr("auth.verify.successTitle", {
|
|
123
|
+
default: "Email verified",
|
|
124
|
+
})}
|
|
125
|
+
</h2>
|
|
126
|
+
<Alert>
|
|
127
|
+
<CheckCircle2 className="size-4" />
|
|
128
|
+
<AlertDescription>
|
|
129
|
+
{tr("auth.verify.success", {
|
|
130
|
+
default: "Your email has been verified successfully.",
|
|
131
|
+
})}
|
|
132
|
+
</AlertDescription>
|
|
133
|
+
</Alert>
|
|
134
|
+
<Button
|
|
135
|
+
nativeButton={false}
|
|
136
|
+
render={<a href={props.loginPath ?? "/auth/login"} />}
|
|
137
|
+
className="w-full"
|
|
138
|
+
>
|
|
139
|
+
{tr("auth.verify.signIn", {
|
|
140
|
+
default: "Sign in to your account",
|
|
141
|
+
})}
|
|
142
|
+
</Button>
|
|
143
|
+
</>
|
|
144
|
+
)}
|
|
145
|
+
{props.step === "error" && (
|
|
146
|
+
<>
|
|
147
|
+
<AlertCircle className="text-destructive size-12" />
|
|
148
|
+
<h2 className="text-center text-lg font-semibold">
|
|
149
|
+
{tr("auth.verify.errorTitle", {
|
|
150
|
+
default: "Email verification failed",
|
|
151
|
+
})}
|
|
152
|
+
</h2>
|
|
153
|
+
<Alert variant="destructive">
|
|
154
|
+
<AlertCircle className="size-4" />
|
|
155
|
+
<AlertDescription>
|
|
156
|
+
{props.error ||
|
|
157
|
+
tr("auth.verify.failed", {
|
|
158
|
+
default:
|
|
159
|
+
"Failed to verify your email. The link may have expired or is invalid.",
|
|
160
|
+
})}
|
|
161
|
+
</AlertDescription>
|
|
162
|
+
</Alert>
|
|
163
|
+
<Button
|
|
164
|
+
nativeButton={false}
|
|
165
|
+
render={<a href={props.loginPath ?? "/auth/login"} />}
|
|
166
|
+
className="w-full"
|
|
167
|
+
>
|
|
168
|
+
{tr("auth.verify.backToSignIn", {
|
|
169
|
+
default: "Back to sign in",
|
|
170
|
+
})}
|
|
171
|
+
</Button>
|
|
172
|
+
</>
|
|
173
|
+
)}
|
|
174
|
+
</CardContent>
|
|
175
|
+
</Card>
|
|
176
|
+
</div>
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
}
|