@eifi1/ui-kit 0.28.0 → 0.29.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 +22 -4
- package/dist/auth/accept-invitation.d.ts +90 -0
- package/dist/auth/accept-invitation.js +117 -0
- package/dist/auth/accept-invitation.js.map +1 -0
- package/dist/auth/auth-errors.d.ts +60 -0
- package/dist/auth/auth-errors.js +32 -0
- package/dist/auth/auth-errors.js.map +1 -0
- package/dist/auth/complete-name-dialog.d.ts +71 -0
- package/dist/auth/complete-name-dialog.js +168 -0
- package/dist/auth/complete-name-dialog.js.map +1 -0
- package/dist/auth/email-tag.d.ts +60 -0
- package/dist/auth/email-tag.js +23 -0
- package/dist/auth/email-tag.js.map +1 -0
- package/dist/auth/forgot-password-form.d.ts +79 -0
- package/dist/auth/forgot-password-form.js +120 -0
- package/dist/auth/forgot-password-form.js.map +1 -0
- package/dist/auth/form-rules.d.ts +27 -0
- package/dist/auth/form-rules.js +23 -0
- package/dist/auth/form-rules.js.map +1 -0
- package/dist/auth/new-password-fields.d.ts +38 -0
- package/dist/auth/new-password-fields.js +54 -0
- package/dist/auth/new-password-fields.js.map +1 -0
- package/dist/auth/not-found-page.d.ts +57 -0
- package/dist/auth/not-found-page.js +40 -0
- package/dist/auth/not-found-page.js.map +1 -0
- package/dist/auth/register-form.d.ts +86 -0
- package/dist/auth/register-form.js +268 -0
- package/dist/auth/register-form.js.map +1 -0
- package/dist/auth/reset-password-form.d.ts +124 -0
- package/dist/auth/reset-password-form.js +164 -0
- package/dist/auth/reset-password-form.js.map +1 -0
- package/dist/auth/sign-in-form.d.ts +243 -0
- package/dist/auth/sign-in-form.js +345 -0
- package/dist/auth/sign-in-form.js.map +1 -0
- package/dist/auth/status-parts.d.ts +78 -0
- package/dist/auth/status-parts.js +83 -0
- package/dist/auth/status-parts.js.map +1 -0
- package/dist/auth/verify-email.d.ts +121 -0
- package/dist/auth/verify-email.js +207 -0
- package/dist/auth/verify-email.js.map +1 -0
- package/dist/chart.d.ts +17 -2
- package/dist/components/amount-input.d.ts +18 -2
- package/dist/components/button-group.d.ts +18 -2
- package/dist/components/calculator.d.ts +18 -2
- package/dist/components/confirm-dialog.d.ts +18 -2
- package/dist/components/copy-button.d.ts +18 -2
- package/dist/components/danger-confirm.d.ts +18 -2
- package/dist/components/facing-pair.d.ts +18 -2
- package/dist/components/file-button.d.ts +18 -2
- package/dist/components/file-dropzone.d.ts +18 -2
- package/dist/components/form-actions.d.ts +18 -2
- package/dist/components/iban-input.d.ts +18 -2
- package/dist/components/language-select.d.ts +18 -9
- package/dist/components/legal-page.d.ts +26 -4
- package/dist/components/legal-page.js +24 -5
- package/dist/components/legal-page.js.map +1 -1
- package/dist/components/legal.d.ts +18 -2
- package/dist/components/legal.js +49 -5
- package/dist/components/legal.js.map +1 -1
- package/dist/components/money-field.d.ts +18 -2
- package/dist/components/number-field.d.ts +18 -2
- package/dist/components/number-input.d.ts +18 -2
- package/dist/components/numpad-sheet.d.ts +18 -2
- package/dist/components/phone-input.d.ts +18 -2
- package/dist/components/series-chart.d.ts +18 -2
- package/dist/components/settings-fields.d.ts +15 -2
- package/dist/components/share-card.d.ts +18 -2
- package/dist/components/text-link.d.ts +18 -2
- package/dist/components/time-input.d.ts +18 -2
- package/dist/components/ui.d.ts +17 -1
- package/dist/components/user-avatar.d.ts +16 -2
- package/dist/components/user-avatar.js +7 -3
- package/dist/components/user-avatar.js.map +1 -1
- package/dist/feedback/feedback-attachment.d.ts +18 -2
- package/dist/feedback/feedback-context.d.ts +18 -2
- package/dist/feedback/feedback-crash.d.ts +18 -2
- package/dist/feedback/feedback-dialog.d.ts +18 -2
- package/dist/feedback/feedback-inbox.d.ts +18 -2
- package/dist/feedback/feedback-labels.d.ts +18 -2
- package/dist/feedback/feedback-menu.d.ts +18 -2
- package/dist/feedback/feedback-record.d.ts +18 -2
- package/dist/feedback/feedback-row-detail.d.ts +18 -2
- package/dist/feedback/feedback-status-undo.d.ts +18 -2
- package/dist/feedback/feedback-submit.d.ts +18 -2
- package/dist/feedback/feedback-swipe.d.ts +18 -2
- package/dist/feedback/feedback-table.d.ts +18 -2
- package/dist/feedback/feedback-thread.d.ts +18 -2
- package/dist/feedback.d.ts +18 -2
- package/dist/hooks/use-file-drop.d.ts +18 -2
- package/dist/i18n/defaults.d.ts +18 -2
- package/dist/i18n/defaults.js +18 -0
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.d.ts +18 -2
- package/dist/i18n/german.js +145 -0
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +18 -2
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.d.ts +13 -201
- package/dist/i18n/locales/de-CH.d.ts +18 -2
- package/dist/i18n/locales/en.d.ts +18 -2
- package/dist/i18n/locales/es.d.ts +18 -2
- package/dist/i18n/locales/es.js +147 -3
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +18 -2
- package/dist/i18n/locales/fr.js +147 -0
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +18 -2
- package/dist/i18n/locales/hu.js +149 -3
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +18 -2
- package/dist/i18n/locales/it.js +146 -1
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +18 -2
- package/dist/i18n/locales/zh.js +146 -1
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +18 -2
- package/dist/i18n/review.js +17 -7
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.js +49 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/person-name.d.ts +69 -0
- package/dist/lib/person-name.js +65 -0
- package/dist/lib/person-name.js.map +1 -0
- package/dist/{kit-labels-SBN0biPl.d.ts → register-form-V1OeNlMr.d.ts} +423 -6
- package/dist/rhf/fields.d.ts +18 -2
- package/dist/rhf/form.d.ts +18 -2
- package/dist/rhf.d.ts +18 -2
- package/dist/shell/app-shell.d.ts +18 -2
- package/dist/shell/company-switcher.d.ts +59 -0
- package/dist/shell/company-switcher.js +85 -0
- package/dist/shell/company-switcher.js.map +1 -0
- package/dist/shell/top-bar-brand.d.ts +18 -2
- package/dist/shell/topbar-action-menu.d.ts +1 -0
- package/dist/shell.d.ts +12 -2
- package/dist/wizard/stepper-nav.d.ts +18 -2
- package/dist/wizard.d.ts +18 -2
- package/package.json +1 -1
- package/src/auth/accept-invitation.tsx +227 -0
- package/src/auth/auth-errors.ts +105 -0
- package/src/auth/complete-name-dialog.tsx +253 -0
- package/src/auth/email-tag.ts +75 -0
- package/src/auth/forgot-password-form.tsx +213 -0
- package/src/auth/form-rules.ts +40 -0
- package/src/auth/new-password-fields.tsx +85 -0
- package/src/auth/not-found-page.tsx +98 -0
- package/src/auth/register-form.tsx +459 -0
- package/src/auth/reset-password-form.tsx +337 -0
- package/src/auth/sign-in-form.tsx +687 -0
- package/src/auth/status-parts.tsx +138 -0
- package/src/auth/verify-email.tsx +358 -0
- package/src/components/legal-page.tsx +35 -0
- package/src/components/legal.tsx +93 -7
- package/src/components/user-avatar.tsx +22 -4
- package/src/i18n/defaults.ts +18 -0
- package/src/i18n/german.ts +153 -0
- package/src/i18n/kit-labels.tsx +27 -0
- package/src/i18n/locales/es.ts +156 -3
- package/src/i18n/locales/fr.ts +157 -0
- package/src/i18n/locales/hu.ts +159 -3
- package/src/i18n/locales/it.ts +154 -1
- package/src/i18n/locales/zh.ts +149 -1
- package/src/i18n/review.ts +15 -6
- package/src/index.ts +63 -1
- package/src/lib/person-name.ts +157 -0
- package/src/shell/company-switcher.tsx +140 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import type { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
3
|
+
import { CheckCircle2, LogIn, TimerOff, XCircle } from "lucide-react";
|
|
4
|
+
import { cn } from "../lib/cn";
|
|
5
|
+
import { useKitLabels } from "../i18n/kit-labels";
|
|
6
|
+
import { useAnnounce } from "../hooks/use-announce";
|
|
7
|
+
import { LoadingState } from "../components/loading-state";
|
|
8
|
+
import { Button, EmptyState } from "../components/ui";
|
|
9
|
+
import { authErrorCode } from "./auth-errors";
|
|
10
|
+
import { OUTCOME_CLASS, STATUS_HEADING_CLASS, useOncePerKey } from "./status-parts";
|
|
11
|
+
import type { AuthHeadingLevel } from "./status-parts";
|
|
12
|
+
|
|
13
|
+
/* ── Labels ──────────────────────────────────────────────────────────────── */
|
|
14
|
+
|
|
15
|
+
/** Every string the page renders — the `acceptInvitation` namespace. keksdose's words
|
|
16
|
+
* where its `/join` page has them (`budget_share.join*`). */
|
|
17
|
+
export interface AcceptInvitationLabels {
|
|
18
|
+
/** The heading. */
|
|
19
|
+
title: string;
|
|
20
|
+
/** While the invitation is accepted. */
|
|
21
|
+
accepting: string;
|
|
22
|
+
/** Accepted, when the app did not say into what. */
|
|
23
|
+
accepted: string;
|
|
24
|
+
/** Accepted, given what it attached the account to — a company, a team, a budget. */
|
|
25
|
+
joined: (name: string) => string;
|
|
26
|
+
/** Into the app, from every outcome but "sign in first". */
|
|
27
|
+
continue: string;
|
|
28
|
+
/** The token is unknown, spent, or for another address. */
|
|
29
|
+
invalid: string;
|
|
30
|
+
expired: string;
|
|
31
|
+
/** The page was opened without a `token`. */
|
|
32
|
+
noToken: string;
|
|
33
|
+
/** Under `invalid` and `expired`: an invitation is re-sent as a new one (§4.4). */
|
|
34
|
+
askAgain: string;
|
|
35
|
+
/** Nobody is signed in: an existing account accepts after sign-in (§4.4). */
|
|
36
|
+
signInFirst: string;
|
|
37
|
+
/** Under it. */
|
|
38
|
+
signInHint: string;
|
|
39
|
+
signIn: string;
|
|
40
|
+
/** Beside "Sign in", with `registerHref`. */
|
|
41
|
+
register: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const DEFAULT_ACCEPT_INVITATION_LABELS: AcceptInvitationLabels = {
|
|
45
|
+
title: "Accept invitation",
|
|
46
|
+
accepting: "Joining…",
|
|
47
|
+
accepted: "Invitation accepted.",
|
|
48
|
+
joined: (name) => `You’ve joined ${name}.`,
|
|
49
|
+
continue: "Continue",
|
|
50
|
+
invalid: "Could not join with this link",
|
|
51
|
+
expired: "This invitation has expired",
|
|
52
|
+
noToken: "This link is missing its invite token.",
|
|
53
|
+
askAgain: "Ask the person who invited you to send a new invitation.",
|
|
54
|
+
signInFirst: "Sign in to accept this invitation",
|
|
55
|
+
signInHint: "Use the account the invitation was sent to.",
|
|
56
|
+
signIn: "Sign in",
|
|
57
|
+
register: "Create account",
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/* ── Types ───────────────────────────────────────────────────────────────── */
|
|
61
|
+
|
|
62
|
+
/** What `onAccept` may resolve with. */
|
|
63
|
+
export interface AcceptInvitationResult {
|
|
64
|
+
/** What the invitation attached the account to, by name — "Example Property Ltd",
|
|
65
|
+
* "Team North", a budget. Said in the confirmation. */
|
|
66
|
+
name?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** What became of an invitation that was not accepted. `signIn`: the server wants a
|
|
70
|
+
* session first (a `401`), which `signedIn` did not know about. */
|
|
71
|
+
export type AcceptInvitationFailure = "invalid" | "expired" | "signIn";
|
|
72
|
+
|
|
73
|
+
type Outcome = "accepted" | AcceptInvitationFailure;
|
|
74
|
+
|
|
75
|
+
export interface AcceptInvitationProps extends Omit<ComponentPropsWithoutRef<"div">, "children" | "title"> {
|
|
76
|
+
/** The invitation's token — the app's `?invite=` / `?token=`. Empty: the link was cut
|
|
77
|
+
* short, and the page says so without asking anyone. */
|
|
78
|
+
token: string;
|
|
79
|
+
/** Someone is signed in on this device. Until then the page asks for a sign-in and
|
|
80
|
+
* sends nothing: accepting attaches the invitation to the SIGNED-IN account. */
|
|
81
|
+
signedIn: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Accept it — `POST /auth/invitations/accept {token}`, once per token, as soon as
|
|
84
|
+
* someone is signed in. Resolve (with what it attached the account to, if the app
|
|
85
|
+
* knows); reject with the client's error.
|
|
86
|
+
*/
|
|
87
|
+
onAccept: (token: string) => Promise<AcceptInvitationResult | void | undefined>;
|
|
88
|
+
/** Which dead end a rejection is. Default: `invitation_expired` is `expired`,
|
|
89
|
+
* anything else `invalid` (§5.2's codes). Map a `401` to `signIn` here. */
|
|
90
|
+
classifyError?: (error: unknown) => AcceptInvitationFailure;
|
|
91
|
+
/** "Continue" — into the app. Default `/`. */
|
|
92
|
+
continueHref?: string;
|
|
93
|
+
/** "Sign in" — the app's `/login`, with a way back here (`?next=…`). Default
|
|
94
|
+
* `/login`. */
|
|
95
|
+
signInHref?: string;
|
|
96
|
+
/** "Create account" beside "Sign in", for an invitation that may lead to a new
|
|
97
|
+
* account — the app's `/register?invite=…`. Left out, none. */
|
|
98
|
+
registerHref?: string;
|
|
99
|
+
/** The heading. Default `labels.title`; `null` draws none, for a page that puts it in
|
|
100
|
+
* `AuthLayout`'s `title` instead. */
|
|
101
|
+
title?: ReactNode;
|
|
102
|
+
/** The heading's level. Default `h2`, under the page's `h1`. */
|
|
103
|
+
headingAs?: AuthHeadingLevel;
|
|
104
|
+
labels?: Partial<AcceptInvitationLabels>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Accept an invitation with an EXISTING account (docs/auth-harmonization.md §4.4): the
|
|
109
|
+
* link leads here, the person signs in if they are not, and the app attaches the
|
|
110
|
+
* invitation — a kastlan user joining a second company, a Kurvenschmiede member a team,
|
|
111
|
+
* a keksdose user a shared budget. A new address never needs this page: its link opens
|
|
112
|
+
* the sign-up form, which spends the invitation itself.
|
|
113
|
+
*
|
|
114
|
+
* keksdose's `JoinSharePage` (features/budgets/join-page.tsx) is the model: it accepts
|
|
115
|
+
* on load, once (the token is single-use, and StrictMode's double effect would send it
|
|
116
|
+
* twice), and shows the outcome where its spinner was. The outcomes: accepted, with the
|
|
117
|
+
* way into the app; not valid; expired (both say to ask for a new invitation, since
|
|
118
|
+
* "resend" mints a new token); or "sign in first", with nothing sent. "Continue" REPLACES
|
|
119
|
+
* this page in the history: the token is spent, so Back must not land here again.
|
|
120
|
+
*/
|
|
121
|
+
export function AcceptInvitation({
|
|
122
|
+
token,
|
|
123
|
+
signedIn,
|
|
124
|
+
onAccept,
|
|
125
|
+
classifyError,
|
|
126
|
+
continueHref = "/",
|
|
127
|
+
signInHref = "/login",
|
|
128
|
+
registerHref,
|
|
129
|
+
title,
|
|
130
|
+
headingAs: Heading = "h2",
|
|
131
|
+
labels: labelsProp,
|
|
132
|
+
className,
|
|
133
|
+
...rest
|
|
134
|
+
}: AcceptInvitationProps) {
|
|
135
|
+
const labels = useKitLabels("acceptInvitation", DEFAULT_ACCEPT_INVITATION_LABELS, labelsProp);
|
|
136
|
+
const [settled, setSettled] = useState<{ token: string; outcome: Outcome; name?: string } | null>(null);
|
|
137
|
+
const { announce, regionProps } = useAnnounce();
|
|
138
|
+
|
|
139
|
+
useOncePerKey(token !== "" && signedIn ? token : null, onAccept, (key, result) => {
|
|
140
|
+
if (result.ok) {
|
|
141
|
+
const name = result.value?.name?.trim() || undefined;
|
|
142
|
+
setSettled({ token: key, outcome: "accepted", name });
|
|
143
|
+
announce(name ? labels.joined(name) : labels.accepted);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const failure: AcceptInvitationFailure =
|
|
147
|
+
classifyError?.(result.error) ?? (authErrorCode(result.error) === "invitation_expired" ? "expired" : "invalid");
|
|
148
|
+
setSettled({ token: key, outcome: failure });
|
|
149
|
+
announce(failure === "signIn" ? labels.signInFirst : labels[failure]);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const outcome: Outcome | "accepting" =
|
|
153
|
+
token === ""
|
|
154
|
+
? "invalid"
|
|
155
|
+
: settled?.token === token
|
|
156
|
+
? settled.outcome
|
|
157
|
+
: signedIn
|
|
158
|
+
? "accepting"
|
|
159
|
+
: "signIn";
|
|
160
|
+
|
|
161
|
+
const continueButton = (variant: "brand" | "secondary") => (
|
|
162
|
+
<Button href={continueHref} replace variant={variant}>
|
|
163
|
+
{labels.continue}
|
|
164
|
+
</Button>
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
let body: ReactNode;
|
|
168
|
+
if (outcome === "accepting") {
|
|
169
|
+
body = <LoadingState size="sm" label={labels.accepting} />;
|
|
170
|
+
} else if (outcome === "accepted") {
|
|
171
|
+
body = (
|
|
172
|
+
<EmptyState
|
|
173
|
+
tone="success"
|
|
174
|
+
icon={<CheckCircle2 />}
|
|
175
|
+
title={settled?.name ? labels.joined(settled.name) : labels.accepted}
|
|
176
|
+
action={continueButton("brand")}
|
|
177
|
+
className={OUTCOME_CLASS}
|
|
178
|
+
/>
|
|
179
|
+
);
|
|
180
|
+
} else if (outcome === "signIn") {
|
|
181
|
+
body = (
|
|
182
|
+
<EmptyState
|
|
183
|
+
icon={<LogIn />}
|
|
184
|
+
title={labels.signInFirst}
|
|
185
|
+
hint={labels.signInHint}
|
|
186
|
+
action={
|
|
187
|
+
<>
|
|
188
|
+
<Button href={signInHref} variant="brand">
|
|
189
|
+
{labels.signIn}
|
|
190
|
+
</Button>
|
|
191
|
+
{registerHref !== undefined && (
|
|
192
|
+
<Button href={registerHref} variant="secondary">
|
|
193
|
+
{labels.register}
|
|
194
|
+
</Button>
|
|
195
|
+
)}
|
|
196
|
+
</>
|
|
197
|
+
}
|
|
198
|
+
className={OUTCOME_CLASS}
|
|
199
|
+
/>
|
|
200
|
+
);
|
|
201
|
+
} else {
|
|
202
|
+
body = (
|
|
203
|
+
<EmptyState
|
|
204
|
+
tone="danger"
|
|
205
|
+
icon={outcome === "expired" ? <TimerOff /> : <XCircle />}
|
|
206
|
+
title={token === "" ? labels.noToken : labels[outcome]}
|
|
207
|
+
hint={labels.askAgain}
|
|
208
|
+
action={signedIn ? continueButton("secondary") : undefined}
|
|
209
|
+
className={OUTCOME_CLASS}
|
|
210
|
+
/>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<div
|
|
216
|
+
{...rest}
|
|
217
|
+
data-state={outcome}
|
|
218
|
+
aria-busy={outcome === "accepting" || undefined}
|
|
219
|
+
className={cn("space-y-3", className)}
|
|
220
|
+
>
|
|
221
|
+
{title === null ? null : <Heading className={STATUS_HEADING_CLASS}>{title ?? labels.title}</Heading>}
|
|
222
|
+
{body}
|
|
223
|
+
{/* Rendered from the start, so the outcome is read when it arrives. */}
|
|
224
|
+
<div {...regionProps} />
|
|
225
|
+
</div>
|
|
226
|
+
);
|
|
227
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The coded refusals of sign-in and sign-up (docs/auth-harmonization.md §5.2): every
|
|
3
|
+
* refusal the auth routes answer carries a machine-readable `code`, and the pages
|
|
4
|
+
* recognise the CODE, never the server's sentence.
|
|
5
|
+
*
|
|
6
|
+
* Today each app's pages print the server's `detail` string (keksdose's
|
|
7
|
+
* `extractApiErrorMessage`), which is English on every locale and, on a credential
|
|
8
|
+
* check, would be an account-enumeration oracle if it ever said more than one thing.
|
|
9
|
+
* keksdose already keys one refusal on a code (`features/budgets/plan-limit.ts`,
|
|
10
|
+
* `402 {detail, code: "plan_budget_limit"}`); §5.2 makes that the rule for auth. Each
|
|
11
|
+
* app switches its server and its pages together (§9).
|
|
12
|
+
*
|
|
13
|
+
* - `invalid_credentials` — unknown address, wrong password AND deactivated account:
|
|
14
|
+
* one answer, in the same time (§2.10). `401`.
|
|
15
|
+
* - `registration_closed` — the sign-up gate refused the address. `403`.
|
|
16
|
+
* - `email_taken` — an account with this address exists. `409`.
|
|
17
|
+
* - `invitation_invalid`, `invitation_expired` — the `invite` token of a sign-up or an
|
|
18
|
+
* accept (§4.4).
|
|
19
|
+
* - `token_invalid` — a one-time token (reset, verification, a sign-in challenge) is
|
|
20
|
+
* unknown, spent or expired.
|
|
21
|
+
* - `account_inactive` — **no server answers it.** §2.10 decided that a deactivated
|
|
22
|
+
* account gets `invalid_credentials`, because a separate answer after a correct
|
|
23
|
+
* password would confirm a leaked one. It stays in the union only for a future server
|
|
24
|
+
* step that is past the password (an admin view, a signed-in refresh) and may say so.
|
|
25
|
+
*/
|
|
26
|
+
export type AuthErrorCode =
|
|
27
|
+
| "invalid_credentials"
|
|
28
|
+
| "registration_closed"
|
|
29
|
+
| "email_taken"
|
|
30
|
+
| "invitation_invalid"
|
|
31
|
+
| "invitation_expired"
|
|
32
|
+
| "token_invalid"
|
|
33
|
+
| "account_inactive";
|
|
34
|
+
|
|
35
|
+
const CODES: ReadonlySet<string> = new Set<AuthErrorCode>([
|
|
36
|
+
"invalid_credentials",
|
|
37
|
+
"registration_closed",
|
|
38
|
+
"email_taken",
|
|
39
|
+
"invitation_invalid",
|
|
40
|
+
"invitation_expired",
|
|
41
|
+
"token_invalid",
|
|
42
|
+
"account_inactive",
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
type Bag = Record<string, unknown>;
|
|
46
|
+
|
|
47
|
+
const isBag = (value: unknown): value is Bag => typeof value === "object" && value !== null;
|
|
48
|
+
|
|
49
|
+
/** A known code, or undefined. */
|
|
50
|
+
function known(value: unknown): AuthErrorCode | undefined {
|
|
51
|
+
return typeof value === "string" && CODES.has(value) ? (value as AuthErrorCode) : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** `{code}` on a parsed body, or FastAPI's `{detail: {code}}` — what an
|
|
55
|
+
* `HTTPException(detail={"code": …})` serialises to. */
|
|
56
|
+
function codeOfBody(body: unknown): AuthErrorCode | undefined {
|
|
57
|
+
if (!isBag(body)) return undefined;
|
|
58
|
+
return known(body.code) ?? (isBag(body.detail) ? known(body.detail.code) : undefined);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The {@link AuthErrorCode} an error carries, or `undefined` when it carries none.
|
|
63
|
+
*
|
|
64
|
+
* Reads the parsed response body wherever the apps' HTTP clients put it, without
|
|
65
|
+
* depending on any of them:
|
|
66
|
+
*
|
|
67
|
+
* 1. `err.response.data` — axios (keksdose's, kastlan's and Kurvenschmiede's clients;
|
|
68
|
+
* keksdose's `isPlanBudgetLimitRefusal` reads the same path);
|
|
69
|
+
* 2. `err.data` — ofetch's `FetchError`, and most `fetch` wrappers that parse the body;
|
|
70
|
+
* 3. `err.body` — the generated OpenAPI clients' `ApiError`;
|
|
71
|
+
* 4. `err` itself — a body thrown as it came (`throw await res.json()`).
|
|
72
|
+
*
|
|
73
|
+
* In each, `code` or FastAPI's nested `detail.code`. Last, `err.code` — but only when
|
|
74
|
+
* it is one of the codes above: axios writes its OWN codes there (`ERR_NETWORK`,
|
|
75
|
+
* `ECONNABORTED`, `ERR_BAD_REQUEST`), and so does Node, so an unknown value is never
|
|
76
|
+
* read as a refusal. The HTTP status is not checked: the code is the contract, and the
|
|
77
|
+
* status differs per refusal (401, 403, 409, 410).
|
|
78
|
+
*/
|
|
79
|
+
export function authErrorCode(err: unknown): AuthErrorCode | undefined {
|
|
80
|
+
if (!isBag(err)) return undefined;
|
|
81
|
+
const response = err.response;
|
|
82
|
+
return (
|
|
83
|
+
(isBag(response) ? codeOfBody(response.data) : undefined) ??
|
|
84
|
+
codeOfBody(err.data) ??
|
|
85
|
+
codeOfBody(err.body) ??
|
|
86
|
+
codeOfBody(err)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Whether `err` is a coded auth refusal — any of them, or the one named:
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* try { await api.register(values) }
|
|
95
|
+
* catch (err) { if (isAuthError(err, "email_taken")) … }
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* The kit's `SignInForm` and `RegisterForm` call it on what their callbacks reject
|
|
99
|
+
* with, so an app's `onSubmit` can simply let its client's error through. See
|
|
100
|
+
* {@link authErrorCode} for the shapes it reads.
|
|
101
|
+
*/
|
|
102
|
+
export function isAuthError(err: unknown, code?: AuthErrorCode): boolean {
|
|
103
|
+
const found = authErrorCode(err);
|
|
104
|
+
return found !== undefined && (code === undefined || found === code);
|
|
105
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { useContext, useEffect, useId, useRef, useState } from "react";
|
|
2
|
+
import type { KeyboardEvent, ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
import { useKitLabels } from "../i18n/kit-labels";
|
|
5
|
+
import { usePromisePending } from "../components/danger-confirm";
|
|
6
|
+
import { DialogFrame } from "../components/dialog-frame";
|
|
7
|
+
import { ModalCloseContext } from "../components/modal";
|
|
8
|
+
import { Button, Input } from "../components/ui";
|
|
9
|
+
import { personNameOk, PERSON_NAME_MAX_LENGTH } from "./form-rules";
|
|
10
|
+
|
|
11
|
+
/** What `CompleteNameDialog` hands `onSave`: both names, trimmed, 1–120 characters —
|
|
12
|
+
* `PATCH /auth/me {first_name, last_name}` (§6.1). */
|
|
13
|
+
export interface CompleteNameValues {
|
|
14
|
+
firstName: string;
|
|
15
|
+
lastName: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Every string the dialog renders — the `completeName` namespace of `<UiKitProvider
|
|
20
|
+
* labels>`, overridable per instance through `labels`.
|
|
21
|
+
*/
|
|
22
|
+
export interface CompleteNameLabels {
|
|
23
|
+
title: string;
|
|
24
|
+
description: string;
|
|
25
|
+
firstName: string;
|
|
26
|
+
lastName: string;
|
|
27
|
+
save: string;
|
|
28
|
+
/** Dismisses the dialog until the next sign-in. */
|
|
29
|
+
later: string;
|
|
30
|
+
/** Under the fields when `onSave` rejected and the app passed no `error`. */
|
|
31
|
+
failed: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const DEFAULT_COMPLETE_NAME_LABELS: CompleteNameLabels = {
|
|
35
|
+
title: "Complete your name",
|
|
36
|
+
description: "First and last name are now asked for separately. Check what is filled in and add what is missing.",
|
|
37
|
+
firstName: "First name",
|
|
38
|
+
lastName: "Last name",
|
|
39
|
+
save: "Save",
|
|
40
|
+
later: "Later",
|
|
41
|
+
failed: "Your name could not be saved. Please try again.",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export interface CompleteNameDialogProps {
|
|
45
|
+
/** What the account holds now — after the migration, the old display name (§3.3). */
|
|
46
|
+
firstName?: string;
|
|
47
|
+
/** Usually empty: that is why the dialog is up. */
|
|
48
|
+
lastName?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Save the names (`PATCH /auth/me`). Resolve and the dialog closes (`onClose(true)`);
|
|
51
|
+
* reject and it stays open with the names kept and `error` — or "Your name could not
|
|
52
|
+
* be saved" — under them.
|
|
53
|
+
*/
|
|
54
|
+
onSave: (values: CompleteNameValues) => Promise<unknown>;
|
|
55
|
+
/**
|
|
56
|
+
* The dialog has closed: `true` after a resolved `onSave`, `false` for "Later", Escape,
|
|
57
|
+
* the backdrop and Back. `false` only DEFERS it: the app shows it again after the
|
|
58
|
+
* next sign-in while `/auth/me` still answers `name_incomplete: true`.
|
|
59
|
+
*/
|
|
60
|
+
onClose: (saved: boolean) => void;
|
|
61
|
+
/** The app's words for the last failed save, instead of `labels.failed`. Hidden again
|
|
62
|
+
* once a name is edited. */
|
|
63
|
+
error?: ReactNode;
|
|
64
|
+
/** Kept-mounted mode, as on `Modal`: left out, the dialog is open while mounted. */
|
|
65
|
+
open?: boolean;
|
|
66
|
+
labels?: Partial<CompleteNameLabels>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* "Complete your name" — asked once after sign-in of a user whose name was migrated
|
|
71
|
+
* (docs/auth-harmonization.md §3.3). keksdose's and Kurvenschmiede's accounts had one
|
|
72
|
+
* `display_name`; it moved whole into `first_name`, `last_name` stayed empty, and
|
|
73
|
+
* nothing was split by guesswork (§2.4). The app shows this while `/auth/me` answers
|
|
74
|
+
* `name_incomplete: true` — never for a demo user.
|
|
75
|
+
*
|
|
76
|
+
* Both names prefilled with what is there; "Save" waits until both have 1–120
|
|
77
|
+
* characters after trimming. **"Later" only defers it**: nothing else waits on a
|
|
78
|
+
* complete name, no page is blocked, and the app asks again at the next sign-in.
|
|
79
|
+
*
|
|
80
|
+
* The promise handling is `ReauthDialog`'s: busy while `onSave` runs (the fields
|
|
81
|
+
* read-only, "Later" disabled, Escape held — a request that has left cannot be called
|
|
82
|
+
* back by closing the dialog), closed on resolve, kept open on reject. Save is a
|
|
83
|
+
* `commit` control, so a `WriteLockProvider` above it locks it with its reason.
|
|
84
|
+
*
|
|
85
|
+
* Focus starts in the first EMPTY field — the last name, as a rule — because filling it
|
|
86
|
+
* in is the whole of what the dialog is for.
|
|
87
|
+
*/
|
|
88
|
+
export function CompleteNameDialog({
|
|
89
|
+
firstName: initialFirst = "",
|
|
90
|
+
lastName: initialLast = "",
|
|
91
|
+
onSave,
|
|
92
|
+
onClose,
|
|
93
|
+
error,
|
|
94
|
+
open,
|
|
95
|
+
labels: labelsProp,
|
|
96
|
+
}: CompleteNameDialogProps) {
|
|
97
|
+
const labels = useKitLabels("completeName", DEFAULT_COMPLETE_NAME_LABELS, labelsProp);
|
|
98
|
+
const [first, setFirst] = useState(initialFirst);
|
|
99
|
+
const [last, setLast] = useState(initialLast);
|
|
100
|
+
// A failed save describes the names that were sent; an edit makes it stale.
|
|
101
|
+
const [failed, setFailed] = useState(false);
|
|
102
|
+
const { pending, run } = usePromisePending();
|
|
103
|
+
const [done, setDone] = useState(false);
|
|
104
|
+
const saved = useRef(false);
|
|
105
|
+
const formId = useId();
|
|
106
|
+
const firstRef = useRef<HTMLInputElement>(null);
|
|
107
|
+
const lastRef = useRef<HTMLInputElement>(null);
|
|
108
|
+
const isOpen = open ?? true;
|
|
109
|
+
|
|
110
|
+
// Reopened (kept-mounted): start again from what the account holds. During render,
|
|
111
|
+
// as ReauthDialog wipes its password, so no frame shows the old draft.
|
|
112
|
+
const [wasOpen, setWasOpen] = useState(isOpen);
|
|
113
|
+
if (wasOpen !== isOpen) {
|
|
114
|
+
setWasOpen(isOpen);
|
|
115
|
+
if (isOpen) {
|
|
116
|
+
setFirst(initialFirst);
|
|
117
|
+
setLast(initialLast);
|
|
118
|
+
setFailed(false);
|
|
119
|
+
setDone(false);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// After Modal's own effect, so its trap has recorded the trigger before focus moves.
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
if (!isOpen) return;
|
|
126
|
+
saved.current = false;
|
|
127
|
+
const target = firstRef.current?.value.trim() ? lastRef.current : firstRef.current;
|
|
128
|
+
target?.focus();
|
|
129
|
+
}, [isOpen]);
|
|
130
|
+
|
|
131
|
+
const canSave = personNameOk(first) && personNameOk(last);
|
|
132
|
+
|
|
133
|
+
const submit = () => {
|
|
134
|
+
if (pending || !canSave) return;
|
|
135
|
+
setFailed(false);
|
|
136
|
+
const values = { firstName: first.trim(), lastName: last.trim() };
|
|
137
|
+
let result: Promise<unknown>;
|
|
138
|
+
try {
|
|
139
|
+
result = Promise.resolve(onSave(values));
|
|
140
|
+
} catch (err) {
|
|
141
|
+
result = Promise.reject(err);
|
|
142
|
+
}
|
|
143
|
+
// A rejection must not go unhandled; usePromisePending clears `pending` on it.
|
|
144
|
+
result.catch(() => setFailed(true));
|
|
145
|
+
run(result, () => {
|
|
146
|
+
saved.current = true;
|
|
147
|
+
setDone(true);
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const edit = (set: (value: string) => void) => (value: string) => {
|
|
152
|
+
set(value);
|
|
153
|
+
setFailed(false);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const message = failed ? (error ?? labels.failed) : undefined;
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<DialogFrame
|
|
160
|
+
open={open}
|
|
161
|
+
title={labels.title}
|
|
162
|
+
description={labels.description}
|
|
163
|
+
onClose={() => onClose(saved.current)}
|
|
164
|
+
onKeyDown={(e: KeyboardEvent<HTMLDivElement>) => {
|
|
165
|
+
if (pending && e.key === "Escape") e.preventDefault();
|
|
166
|
+
}}
|
|
167
|
+
aria-busy={pending || undefined}
|
|
168
|
+
actions={
|
|
169
|
+
<CompleteNameActions
|
|
170
|
+
formId={formId}
|
|
171
|
+
done={done}
|
|
172
|
+
busy={pending}
|
|
173
|
+
canSave={canSave}
|
|
174
|
+
laterLabel={labels.later}
|
|
175
|
+
saveLabel={labels.save}
|
|
176
|
+
/>
|
|
177
|
+
}
|
|
178
|
+
>
|
|
179
|
+
<form
|
|
180
|
+
id={formId}
|
|
181
|
+
noValidate
|
|
182
|
+
className="grid gap-3 @container"
|
|
183
|
+
onSubmit={(e) => {
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
submit();
|
|
186
|
+
}}
|
|
187
|
+
>
|
|
188
|
+
<div className="grid gap-3 @xs:grid-cols-2">
|
|
189
|
+
<Input
|
|
190
|
+
ref={firstRef}
|
|
191
|
+
name="given-name"
|
|
192
|
+
autoComplete="given-name"
|
|
193
|
+
label={labels.firstName}
|
|
194
|
+
value={first}
|
|
195
|
+
onChange={(e) => edit(setFirst)(e.target.value)}
|
|
196
|
+
maxLength={PERSON_NAME_MAX_LENGTH}
|
|
197
|
+
readOnly={pending}
|
|
198
|
+
required
|
|
199
|
+
/>
|
|
200
|
+
<Input
|
|
201
|
+
ref={lastRef}
|
|
202
|
+
name="family-name"
|
|
203
|
+
autoComplete="family-name"
|
|
204
|
+
label={labels.lastName}
|
|
205
|
+
value={last}
|
|
206
|
+
onChange={(e) => edit(setLast)(e.target.value)}
|
|
207
|
+
maxLength={PERSON_NAME_MAX_LENGTH}
|
|
208
|
+
readOnly={pending}
|
|
209
|
+
required
|
|
210
|
+
/>
|
|
211
|
+
</div>
|
|
212
|
+
{message !== undefined && (
|
|
213
|
+
<p role="alert" className="text-xs text-[var(--danger)]">
|
|
214
|
+
{message}
|
|
215
|
+
</p>
|
|
216
|
+
)}
|
|
217
|
+
</form>
|
|
218
|
+
</DialogFrame>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** The actions row, inside the `Modal`, where its animated close is in context: a
|
|
223
|
+
* resolved save lowers the panel through it, as "Later" and Escape do. */
|
|
224
|
+
function CompleteNameActions({
|
|
225
|
+
formId,
|
|
226
|
+
done,
|
|
227
|
+
busy,
|
|
228
|
+
canSave,
|
|
229
|
+
laterLabel,
|
|
230
|
+
saveLabel,
|
|
231
|
+
}: {
|
|
232
|
+
formId: string;
|
|
233
|
+
done: boolean;
|
|
234
|
+
busy: boolean;
|
|
235
|
+
canSave: boolean;
|
|
236
|
+
laterLabel: string;
|
|
237
|
+
saveLabel: string;
|
|
238
|
+
}) {
|
|
239
|
+
const close = useContext(ModalCloseContext);
|
|
240
|
+
useEffect(() => {
|
|
241
|
+
if (done) close?.();
|
|
242
|
+
}, [done, close]);
|
|
243
|
+
return (
|
|
244
|
+
<>
|
|
245
|
+
<Button type="button" variant="ghost" disabled={busy} onClick={() => close?.()}>
|
|
246
|
+
{laterLabel}
|
|
247
|
+
</Button>
|
|
248
|
+
<Button type="submit" form={formId} commit disabled={!busy && !canSave} pending={busy}>
|
|
249
|
+
{saveLabel}
|
|
250
|
+
</Button>
|
|
251
|
+
</>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The address tag: `you@example.com` → `you+kastlan@example.com`, the app's own name as
|
|
3
|
+
* a sub-address of the address a person types for themselves (docs/auth-harmonization.md
|
|
4
|
+
* §4.5, Marcel 2026-10-05). Lifted from keksdose (`features/auth/email-tag.ts`, feedback
|
|
5
|
+
* dev#481), where the tag was the constant `keksdose`; here it is the app's.
|
|
6
|
+
*
|
|
7
|
+
* **Structurally valid is not the same as deliverable.** `+` is an ordinary character in
|
|
8
|
+
* the local part under RFC 5322, and sub-addressing — `user+tag@host` delivered to
|
|
9
|
+
* `user@host` — is specified (RFC 5233). But it is specified as a convention the
|
|
10
|
+
* RECEIVING server may implement: Gmail, Outlook, iCloud, Fastmail and Proton do; many
|
|
11
|
+
* Exchange installs, small hosters and corporate filters do not, and some web forms
|
|
12
|
+
* refuse the character outright.
|
|
13
|
+
*
|
|
14
|
+
* Which is why every caller OFFERS the result and never applies it. Silently registering
|
|
15
|
+
* somebody as `you+kastlan@example.com` would send the verification mail — the one
|
|
16
|
+
* message the account depends on — down a delivery path nobody checked, and make the
|
|
17
|
+
* address they sign in with one they never typed. The tag is a convenience for the
|
|
18
|
+
* person who wants it: one click, with the exact resulting address on the button
|
|
19
|
+
* (`RegisterForm` does this with its `emailTag`).
|
|
20
|
+
*
|
|
21
|
+
* The tagged address is then the identity. The server trims and lower-cases an address
|
|
22
|
+
* at every entry and never strips a tag, so `you@…` and `you+kastlan@…` are two
|
|
23
|
+
* different accounts; sign-in stays exact (§4.5), which is why `SignInForm`'s hint after
|
|
24
|
+
* a failed sign-in names the tagged address rather than trying it.
|
|
25
|
+
*
|
|
26
|
+
* Offer it only where a person types an address FOR THEMSELVES — sign-up, a later email
|
|
27
|
+
* change in the profile — never in a field for someone else's (an invite dialog, a
|
|
28
|
+
* share), where the tag would be a guess about another person's mail server.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** What a tag may be: the app's name, lower case — letters, digits, `.`, `_`, `-`. A
|
|
32
|
+
* space, `@` or `+` would make the result something other than a sub-address. */
|
|
33
|
+
const TAG_SHAPE = /^[a-z0-9][a-z0-9._-]*$/;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* `taggedEmail("you@example.com", "kastlan")` → `"you+kastlan@example.com"`, or `null`
|
|
37
|
+
* when there is nothing to offer:
|
|
38
|
+
*
|
|
39
|
+
* - the address is not complete enough to split — no local part, no domain, or a
|
|
40
|
+
* domain without an inner dot (the shape the field's own `type="email"` accepts), so
|
|
41
|
+
* the offer cannot appear before the address is plausible or linger once it stops
|
|
42
|
+
* being one;
|
|
43
|
+
* - the address already carries a `+` — the person's own scheme wins, and stacking a
|
|
44
|
+
* second tag on it would be wrong;
|
|
45
|
+
* - the tag is empty or not a plain name (see `TAG_SHAPE`).
|
|
46
|
+
*
|
|
47
|
+
* The tag is the app's name in lower case (`keksdose`, `kastlan`, `kurvenschmiede`); it
|
|
48
|
+
* is trimmed and lower-cased here, so `"Kastlan"` gives the same answer. The address is
|
|
49
|
+
* trimmed and otherwise kept as typed — normalising it is the server's job (server-kit's
|
|
50
|
+
* `normalise_email`).
|
|
51
|
+
*/
|
|
52
|
+
export function taggedEmail(email: string, tag: string): string | null {
|
|
53
|
+
const name = tag.trim().toLowerCase();
|
|
54
|
+
if (!TAG_SHAPE.test(name)) return null;
|
|
55
|
+
const parts = emailParts(email);
|
|
56
|
+
if (!parts || parts.local.includes("+")) return null;
|
|
57
|
+
return `${parts.local}+${name}@${parts.domain}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The trimmed address split at its last `@`, or `null` while it is not complete enough
|
|
62
|
+
* to split: no local part, no domain, or a domain without an inner dot — the shape the
|
|
63
|
+
* field's own `type="email"` accepts.
|
|
64
|
+
*
|
|
65
|
+
* @internal `RegisterForm` gates its submit on it; not part of the barrel.
|
|
66
|
+
*/
|
|
67
|
+
export function emailParts(email: string): { local: string; domain: string } | null {
|
|
68
|
+
const trimmed = email.trim();
|
|
69
|
+
const at = trimmed.lastIndexOf("@");
|
|
70
|
+
if (at <= 0 || at === trimmed.length - 1) return null;
|
|
71
|
+
const local = trimmed.slice(0, at);
|
|
72
|
+
const domain = trimmed.slice(at + 1);
|
|
73
|
+
if (!domain.includes(".") || domain.startsWith(".") || domain.endsWith(".")) return null;
|
|
74
|
+
return { local, domain };
|
|
75
|
+
}
|