@eifi1/ui-kit 0.29.0 → 0.31.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 +65 -6
- package/dist/account/account-parts.d.ts +21 -0
- package/dist/account/account-parts.js +40 -0
- package/dist/account/account-parts.js.map +1 -0
- package/dist/account/data-export-setting.d.ts +73 -0
- package/dist/account/data-export-setting.js +114 -0
- package/dist/account/data-export-setting.js.map +1 -0
- package/dist/account/delete-account-setting.d.ts +95 -0
- package/dist/account/delete-account-setting.js +200 -0
- package/dist/account/delete-account-setting.js.map +1 -0
- package/dist/account/email-change-setting.d.ts +136 -0
- package/dist/account/email-change-setting.js +278 -0
- package/dist/account/email-change-setting.js.map +1 -0
- package/dist/account/sessions-setting.d.ts +110 -0
- package/dist/account/sessions-setting.js +147 -0
- package/dist/account/sessions-setting.js.map +1 -0
- package/dist/admin/admin-action-confirm.d.ts +95 -0
- package/dist/admin/admin-action-confirm.js +276 -0
- package/dist/admin/admin-action-confirm.js.map +1 -0
- package/dist/admin/admin-action-log.d.ts +105 -0
- package/dist/admin/admin-action-log.js +153 -0
- package/dist/admin/admin-action-log.js.map +1 -0
- package/dist/admin/admin-parts.d.ts +40 -0
- package/dist/admin/admin-parts.js +45 -0
- package/dist/admin/admin-parts.js.map +1 -0
- package/dist/admin/invitations-panel.d.ts +95 -0
- package/dist/admin/invitations-panel.js +290 -0
- package/dist/admin/invitations-panel.js.map +1 -0
- package/dist/admin/reviewer-scope-editor.d.ts +95 -0
- package/dist/admin/reviewer-scope-editor.js +134 -0
- package/dist/admin/reviewer-scope-editor.js.map +1 -0
- package/dist/admin/role-select.d.ts +95 -0
- package/dist/admin/role-select.js +128 -0
- package/dist/admin/role-select.js.map +1 -0
- package/dist/admin/transfer-ownership-dialog.d.ts +95 -0
- package/dist/admin/transfer-ownership-dialog.js +83 -0
- package/dist/admin/transfer-ownership-dialog.js.map +1 -0
- package/dist/admin/user-roster.d.ts +95 -0
- package/dist/admin/user-roster.js +285 -0
- package/dist/admin/user-roster.js.map +1 -0
- package/dist/auth/auth-errors.d.ts +103 -6
- package/dist/auth/auth-errors.js +68 -2
- package/dist/auth/auth-errors.js.map +1 -1
- package/dist/auth/forgot-password-form.d.ts +10 -3
- package/dist/auth/forgot-password-form.js +6 -3
- package/dist/auth/forgot-password-form.js.map +1 -1
- package/dist/auth/register-form.d.ts +21 -12
- package/dist/auth/register-form.js +6 -4
- package/dist/auth/register-form.js.map +1 -1
- package/dist/auth/reset-password-form.d.ts +10 -3
- package/dist/auth/reset-password-form.js +6 -3
- package/dist/auth/reset-password-form.js.map +1 -1
- package/dist/auth/sign-in-form.d.ts +75 -9
- package/dist/auth/sign-in-form.js +105 -15
- package/dist/auth/sign-in-form.js.map +1 -1
- package/dist/auth/verify-email.d.ts +7 -2
- package/dist/auth/verify-email.js +44 -8
- package/dist/auth/verify-email.js.map +1 -1
- package/dist/chart.d.ts +20 -11
- package/dist/components/account-chips.d.ts +47 -7
- package/dist/components/account-chips.js +19 -3
- package/dist/components/account-chips.js.map +1 -1
- package/dist/components/account-settings-labels.d.ts +24 -1
- package/dist/components/account-settings-labels.js +6 -2
- package/dist/components/account-settings-labels.js.map +1 -1
- package/dist/components/account-settings.d.ts +69 -8
- package/dist/components/account-settings.js +133 -25
- package/dist/components/account-settings.js.map +1 -1
- package/dist/components/amount-input.d.ts +21 -12
- package/dist/components/button-group.d.ts +21 -12
- package/dist/components/calculator.d.ts +21 -12
- package/dist/components/confirm-dialog.d.ts +21 -12
- package/dist/components/copy-button.d.ts +18 -9
- package/dist/components/danger-confirm.d.ts +21 -12
- package/dist/components/data-table.js +8 -1
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.js +9 -4
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/facing-pair.d.ts +21 -12
- package/dist/components/file-button.d.ts +21 -12
- package/dist/components/file-dropzone.d.ts +21 -12
- package/dist/components/form-actions.d.ts +21 -12
- package/dist/components/iban-input.d.ts +21 -12
- package/dist/components/language-select.d.ts +21 -12
- package/dist/components/legal-page.d.ts +21 -12
- package/dist/components/legal.d.ts +21 -12
- package/dist/components/money-field.d.ts +21 -12
- package/dist/components/number-field.d.ts +21 -12
- package/dist/components/number-input.d.ts +21 -12
- package/dist/components/numpad-sheet.d.ts +21 -12
- package/dist/components/passkeys-setting.js +2 -1
- package/dist/components/passkeys-setting.js.map +1 -1
- package/dist/components/phone-input.d.ts +21 -12
- package/dist/components/series-chart.d.ts +21 -12
- package/dist/components/settings-fields.d.ts +55 -13
- package/dist/components/settings-fields.js +20 -1
- package/dist/components/settings-fields.js.map +1 -1
- package/dist/components/share-card.d.ts +20 -11
- package/dist/components/text-link.d.ts +21 -12
- package/dist/components/time-input.d.ts +21 -12
- package/dist/components/ui.d.ts +17 -8
- package/dist/{register-form-V1OeNlMr.d.ts → delete-account-setting-DCFS5Vof.d.ts} +6612 -5612
- package/dist/demo/demo-banner.d.ts +51 -0
- package/dist/demo/demo-banner.js +97 -0
- package/dist/demo/demo-banner.js.map +1 -0
- package/dist/demo/demo-countdown.d.ts +58 -0
- package/dist/demo/demo-countdown.js +79 -0
- package/dist/demo/demo-countdown.js.map +1 -0
- package/dist/demo/demo-ended.d.ts +45 -0
- package/dist/demo/demo-ended.js +42 -0
- package/dist/demo/demo-ended.js.map +1 -0
- package/dist/demo/demo-labels.d.ts +53 -0
- package/dist/demo/demo-labels.js +29 -0
- package/dist/demo/demo-labels.js.map +1 -0
- package/dist/demo/demo-session.d.ts +30 -0
- package/dist/demo/demo-session.js +8 -0
- package/dist/demo/demo-session.js.map +1 -0
- package/dist/demo/demo-start.d.ts +54 -0
- package/dist/demo/demo-start.js +68 -0
- package/dist/demo/demo-start.js.map +1 -0
- package/dist/feedback/feedback-attachment.d.ts +21 -12
- package/dist/feedback/feedback-context.d.ts +21 -12
- package/dist/feedback/feedback-crash.d.ts +21 -12
- package/dist/feedback/feedback-dialog.d.ts +21 -12
- package/dist/feedback/feedback-inbox.d.ts +21 -12
- package/dist/feedback/feedback-inbox.js +12 -2
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback/feedback-labels.d.ts +21 -12
- package/dist/feedback/feedback-labels.js +1 -0
- package/dist/feedback/feedback-labels.js.map +1 -1
- package/dist/feedback/feedback-menu.d.ts +21 -12
- package/dist/feedback/feedback-record.d.ts +21 -12
- package/dist/feedback/feedback-record.js +2 -0
- package/dist/feedback/feedback-record.js.map +1 -1
- package/dist/feedback/feedback-row-detail.d.ts +21 -12
- package/dist/feedback/feedback-row-detail.js +7 -0
- package/dist/feedback/feedback-row-detail.js.map +1 -1
- package/dist/feedback/feedback-status-undo.d.ts +21 -12
- package/dist/feedback/feedback-submit.d.ts +21 -12
- package/dist/feedback/feedback-swipe.d.ts +22 -13
- package/dist/feedback/feedback-swipe.js.map +1 -1
- package/dist/feedback/feedback-table.d.ts +18 -9
- package/dist/feedback/feedback-thread.d.ts +21 -12
- package/dist/feedback.d.ts +21 -12
- package/dist/hooks/use-anchored-panel.d.ts +6 -2
- package/dist/hooks/use-anchored-panel.js +2 -1
- package/dist/hooks/use-anchored-panel.js.map +1 -1
- package/dist/hooks/use-file-drop.d.ts +21 -12
- package/dist/i18n/defaults.d.ts +21 -12
- package/dist/i18n/defaults.js +28 -0
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.d.ts +21 -12
- package/dist/i18n/german.js +298 -12
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +14 -5
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.d.ts +15 -6
- package/dist/i18n/locales/de-CH.d.ts +21 -12
- package/dist/i18n/locales/en.d.ts +21 -12
- package/dist/i18n/locales/es.d.ts +21 -12
- package/dist/i18n/locales/es.js +287 -10
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +21 -12
- package/dist/i18n/locales/fr.js +290 -7
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +21 -12
- package/dist/i18n/locales/hu.js +288 -12
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +21 -12
- package/dist/i18n/locales/it.js +289 -7
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +21 -12
- package/dist/i18n/locales/zh.js +279 -7
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +21 -12
- package/dist/i18n/review.js +50 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +31 -4
- package/dist/index.js +148 -0
- package/dist/index.js.map +1 -1
- package/dist/landing/access.d.ts +48 -0
- package/dist/landing/access.js +38 -0
- package/dist/landing/access.js.map +1 -0
- package/dist/landing/landing-actions.d.ts +138 -0
- package/dist/landing/landing-actions.js +39 -0
- package/dist/landing/landing-actions.js.map +1 -0
- package/dist/landing/landing-labels.d.ts +43 -0
- package/dist/landing/landing-labels.js +23 -0
- package/dist/landing/landing-labels.js.map +1 -0
- package/dist/landing/landing-sections.d.ts +218 -0
- package/dist/landing/landing-sections.js +167 -0
- package/dist/landing/landing-sections.js.map +1 -0
- package/dist/landing/page-seo.d.ts +99 -0
- package/dist/landing/page-seo.js +121 -0
- package/dist/landing/page-seo.js.map +1 -0
- package/dist/landing/public-header.d.ts +148 -0
- package/dist/landing/public-header.js +49 -0
- package/dist/landing/public-header.js.map +1 -0
- package/dist/landing/routing.d.ts +218 -0
- package/dist/landing/routing.js +81 -0
- package/dist/landing/routing.js.map +1 -0
- package/dist/rhf/fields.d.ts +21 -12
- package/dist/rhf/form.d.ts +21 -12
- package/dist/rhf.d.ts +21 -12
- package/dist/settings/settings-catalogue.d.ts +84 -0
- package/dist/settings/settings-catalogue.js +47 -0
- package/dist/settings/settings-catalogue.js.map +1 -0
- package/dist/settings/settings-context.d.ts +31 -0
- package/dist/settings/settings-context.js +11 -0
- package/dist/settings/settings-context.js.map +1 -0
- package/dist/settings/settings-heading.d.ts +50 -0
- package/dist/settings/settings-heading.js +27 -0
- package/dist/settings/settings-heading.js.map +1 -0
- package/dist/settings/settings-labels.d.ts +41 -0
- package/dist/settings/settings-labels.js +38 -0
- package/dist/settings/settings-labels.js.map +1 -0
- package/dist/settings/settings-layout.d.ts +77 -0
- package/dist/settings/settings-layout.js +242 -0
- package/dist/settings/settings-layout.js.map +1 -0
- package/dist/settings/settings-section.d.ts +133 -0
- package/dist/settings/settings-section.js +63 -0
- package/dist/settings/settings-section.js.map +1 -0
- package/dist/settings/use-account-language.d.ts +83 -0
- package/dist/settings/use-account-language.js +62 -0
- package/dist/settings/use-account-language.js.map +1 -0
- package/dist/settings/use-settings-focus.d.ts +34 -0
- package/dist/settings/use-settings-focus.js +77 -0
- package/dist/settings/use-settings-focus.js.map +1 -0
- package/dist/settings/use-settings-route.d.ts +118 -0
- package/dist/settings/use-settings-route.js +120 -0
- package/dist/settings/use-settings-route.js.map +1 -0
- package/dist/shell/app-shell.d.ts +27 -12
- package/dist/shell/app-shell.js +3 -2
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/shell/top-bar-brand.d.ts +21 -12
- package/dist/shell.d.ts +25 -6
- package/dist/shell.js +56 -0
- package/dist/shell.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +21 -12
- package/dist/wizard.d.ts +21 -12
- package/package.json +2 -1
- package/src/account/account-parts.ts +67 -0
- package/src/account/data-export-setting.tsx +219 -0
- package/src/account/delete-account-setting.tsx +363 -0
- package/src/account/email-change-setting.tsx +454 -0
- package/src/account/sessions-setting.tsx +284 -0
- package/src/admin/admin-action-confirm.tsx +495 -0
- package/src/admin/admin-action-log.tsx +297 -0
- package/src/admin/admin-parts.ts +82 -0
- package/src/admin/invitations-panel.tsx +523 -0
- package/src/admin/reviewer-scope-editor.tsx +234 -0
- package/src/admin/role-select.tsx +286 -0
- package/src/admin/transfer-ownership-dialog.tsx +172 -0
- package/src/admin/user-roster.tsx +573 -0
- package/src/auth/auth-errors.ts +196 -8
- package/src/auth/forgot-password-form.tsx +21 -5
- package/src/auth/register-form.tsx +24 -6
- package/src/auth/reset-password-form.tsx +19 -5
- package/src/auth/sign-in-form.tsx +241 -38
- package/src/auth/verify-email.tsx +59 -8
- package/src/components/account-chips.tsx +64 -7
- package/src/components/account-settings-labels.ts +28 -1
- package/src/components/account-settings.tsx +231 -34
- package/src/components/data-table.tsx +8 -0
- package/src/components/date-picker.tsx +9 -4
- package/src/components/passkeys-setting.tsx +2 -1
- package/src/components/settings-fields.tsx +50 -1
- package/src/demo/demo-banner.tsx +159 -0
- package/src/demo/demo-countdown.ts +141 -0
- package/src/demo/demo-ended.tsx +89 -0
- package/src/demo/demo-labels.ts +78 -0
- package/src/demo/demo-session.ts +32 -0
- package/src/demo/demo-start.tsx +150 -0
- package/src/feedback/feedback-inbox.tsx +21 -8
- package/src/feedback/feedback-labels.ts +2 -1
- package/src/feedback/feedback-record.ts +10 -7
- package/src/feedback/feedback-row-detail.tsx +28 -4
- package/src/feedback/feedback-swipe.tsx +1 -1
- package/src/hooks/use-anchored-panel.ts +14 -3
- package/src/i18n/defaults.ts +28 -0
- package/src/i18n/german.ts +327 -5
- package/src/i18n/kit-labels.tsx +42 -0
- package/src/i18n/locales/es.ts +313 -3
- package/src/i18n/locales/fr.ts +316 -0
- package/src/i18n/locales/hu.ts +308 -5
- package/src/i18n/locales/it.ts +313 -0
- package/src/i18n/locales/zh.ts +286 -0
- package/src/i18n/review.ts +49 -0
- package/src/index.ts +184 -0
- package/src/landing/access.ts +97 -0
- package/src/landing/landing-actions.tsx +92 -0
- package/src/landing/landing-labels.ts +59 -0
- package/src/landing/landing-sections.tsx +337 -0
- package/src/landing/page-seo.ts +251 -0
- package/src/landing/public-header.tsx +120 -0
- package/src/landing/routing.tsx +209 -0
- package/src/settings/settings-catalogue.ts +132 -0
- package/src/settings/settings-context.ts +33 -0
- package/src/settings/settings-heading.tsx +65 -0
- package/src/settings/settings-labels.ts +75 -0
- package/src/settings/settings-layout.tsx +379 -0
- package/src/settings/settings-section.tsx +108 -0
- package/src/settings/use-account-language.ts +146 -0
- package/src/settings/use-settings-focus.ts +120 -0
- package/src/settings/use-settings-route.ts +258 -0
- package/src/shell/app-shell.tsx +10 -2
- package/src/shell.ts +45 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/register-form.tsx"],"sourcesContent":["import { useEffect, useId, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, FormEvent, ReactNode } from \"react\";\n\nimport { useKitLabels, useKitLocale } from \"../i18n/kit-labels\";\nimport { KIT_LANGUAGES, resolveLanguage } from \"../i18n/languages\";\nimport type { KitLanguageCode } from \"../i18n/languages\";\nimport { cn } from \"../lib/cn\";\nimport { AlertBanner } from \"../components/alert-banner\";\nimport { hasMessage } from \"../components/choice-parts\";\nimport { LanguageSelect } from \"../components/language-select\";\nimport { LegalAcceptCheckbox } from \"../components/legal-page\";\nimport { TextLink } from \"../components/text-link\";\nimport { Button, Input } from \"../components/ui\";\nimport { authErrorCode } from \"./auth-errors\";\nimport { emailParts, taggedEmail } from \"./email-tag\";\nimport { newPasswordProblem, personNameOk, PERSON_NAME_MAX_LENGTH } from \"./form-rules\";\nimport { NewPasswordFields } from \"./new-password-fields\";\n\n/** What `RegisterForm` hands `onSubmit` — the core of `POST /auth/register` (§4.2). The\n * app adds its own fields (kastlan's company, keksdose's currency) and the\n * `invite_token` it read from the URL. */\nexport interface RegisterValues {\n /** Trimmed, 1–120 characters. */\n firstName: string;\n /** Trimmed, 1–120 characters. */\n lastName: string;\n /** Trimmed. Lower-casing is the server's (§3.1); a tag is never stripped (§4.5). */\n email: string;\n /** As typed: at least 8 characters, at most 72 bytes. */\n password: string;\n /** The language picked — one of `languages` — for every mail to the user (§3.1). */\n locale: KitLanguageCode;\n}\n\n/**\n * Every string `RegisterForm` renders — the `register` namespace of `<UiKitProvider\n * labels>`, overridable per instance through `labels`. keksdose's words where it has\n * them. The terms checkbox speaks `legal.accept`, the strength meter `passwordStrength`.\n */\nexport interface RegisterLabels {\n firstName: string;\n lastName: string;\n email: string;\n /** The address-tag button (§4.5), given the exact address it would use — and, with an\n * invitation, the button back to the invited address. */\n emailTagUse: (address: string) => string;\n /** The line after the address-tag button. */\n emailTagHint: string;\n /** Under an invited (read-only) email field. */\n invitedEmailHint: string;\n /** Once the invitee took the tagged address: it is not the invited one, so it is\n * confirmed by a mail of its own (§4.3). */\n invitedTagNote: string;\n password: string;\n confirmPassword: string;\n passwordMismatch: string;\n language: string;\n /** The submit button. */\n submit: string;\n /** Before the link to `signInHref`. */\n haveAccount: string;\n /** The link to `signInHref`. */\n signIn: string;\n /** `email_taken`, under the email field. */\n emailTaken: string;\n /** `registration_closed` — the gate refused the address (§4.3). */\n registrationClosed: string;\n /** `invitation_invalid` — the invitation link is unknown or spent. */\n invitationInvalid: string;\n /** `invitation_expired`. */\n invitationExpired: string;\n /** Any other failure. */\n failed: string;\n}\n\nexport const DEFAULT_REGISTER_LABELS: RegisterLabels = {\n firstName: \"First name\",\n lastName: \"Last name\",\n email: \"Email\",\n emailTagUse: (address) => `Use ${address}`,\n emailTagHint:\n \"Many providers deliver name+tag@… to the same inbox, so mail from this app is easy to filter and trace. Check yours does before you rely on it: you would sign in with the tagged address.\",\n invitedEmailHint: \"The address your invitation was sent to.\",\n invitedTagNote: \"The tagged address gets a confirmation mail of its own.\",\n password: \"Password\",\n confirmPassword: \"Repeat password\",\n passwordMismatch: \"The passwords don't match.\",\n language: \"Language\",\n submit: \"Create account\",\n haveAccount: \"Already have an account?\",\n signIn: \"Sign in\",\n emailTaken: \"An account with this email address already exists.\",\n registrationClosed: \"New accounts are by invitation only. Ask the operator to invite your email address.\",\n invitationInvalid: \"This invitation link is not valid.\",\n invitationExpired: \"This invitation has expired. Ask for a new one.\",\n failed: \"Registration failed. Please try again.\",\n};\n\nexport interface RegisterFormProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"onSubmit\" | \"children\"> {\n /**\n * The form was submitted with everything filled in. Send it (`POST /auth/register`,\n * §4.2) and resolve once the user is signed in, or reject with the client's error:\n * `email_taken` shows under the email field, `registration_closed` and the\n * invitation codes above the button, anything else as \"Registration failed\". The form\n * never sends a request itself (§8): keksdose must see the password on its way.\n *\n * On resolve the form stays busy while the app navigates.\n */\n onSubmit: (values: RegisterValues) => Promise<unknown>;\n /**\n * The app's address tag (`\"kastlan\"`, §4.5). Once the email is plausible, a button\n * under it offers the tagged address — \"Use ada+kastlan@example.com\" — with a line on\n * why; one click puts it in the field. Never applied on its own. Left out, no offer.\n */\n emailTag?: string;\n /**\n * The address of the invitation this sign-up comes from (§4.4): the field starts with\n * it and is read-only. With `emailTag`, the invitee may still take the tagged form of\n * it — the server accepts exactly that variant — and go back.\n */\n invitedEmail?: string;\n /**\n * The language field's value — controlled. Pass the app's UI language\n * (`i18n.resolvedLanguage`) with `onLocaleChange` switching it, and the field IS the\n * app's language switch, with no copy of its own to drift from a second switcher on\n * the page (keksdose's register page has one in its header). Any tag; it shows (and\n * submits) the offered code it resolves to. Left out, the form keeps its own, starting\n * from `defaultLocale`, else the provider's language, else the browser's.\n */\n locale?: string;\n /** The uncontrolled language field's start value. */\n defaultLocale?: string;\n /** A language was picked. */\n onLocaleChange?: (code: KitLanguageCode) => void;\n /** The languages to offer, in order. Default all seven. */\n languages?: readonly KitLanguageCode[];\n /**\n * The app's own language field in place of the kit's select — keksdose's\n * `LanguageSetting` bound to its i18n. `null` draws none (an app with one language);\n * the submitted `locale` is then `locale`'s.\n */\n languageField?: ReactNode;\n /** Above the form — keksdose's closed-beta banner. */\n aboveForm?: ReactNode;\n /** Under the email field and its tag offer — an app's own hint. */\n underEmail?: ReactNode;\n /** The app's sign-up fields (§4.1 item 7): kastlan's Company, keksdose's reporting\n * currency. Their values are the app's; say whether they are complete with\n * `appFieldsComplete`. */\n appFields?: ReactNode;\n /** After the app fields, before the terms — keksdose's privacy-mode note. */\n afterFields?: ReactNode;\n /** Whether the app fields are filled in as required — kastlan's Company without an\n * invitation. The submit waits for it. Default `true`. */\n appFieldsComplete?: boolean;\n /** The terms checkbox's links. Default `/terms` and `/privacy`. */\n termsHref?: string;\n privacyHref?: string;\n /** \"Already have an account? Sign in\" goes here — `/login`. Left out, no line. */\n signInHref?: string;\n /** The app's own words for a failure the kit cannot know (a throttled attempt), or\n * `undefined` for the kit's. Asked first, for every failure. */\n describeError?: (error: unknown) => ReactNode | undefined;\n labels?: Partial<RegisterLabels>;\n}\n\nconst ALL_CODES: readonly KitLanguageCode[] = KIT_LANGUAGES.map((language) => language.code);\n\n/** The browser's languages, in its order — absent outside a browser. */\nfunction browserLanguages(): readonly string[] {\n if (typeof navigator === \"undefined\") return [];\n return navigator.languages?.length ? navigator.languages : [navigator.language];\n}\n\ntype Busy = \"sending\" | \"done\" | null;\n\n/**\n * Sign-up for every app (docs/auth-harmonization.md §4.1, §8): first and last name,\n * email with the address-tag offer, password with the strength meter and its\n * confirmation, language, the app's own fields in a slot, and the terms. keksdose's\n * `RegisterPage` (features/auth/register-page.tsx) with its slots made props.\n *\n * **It never sends a request.** `onSubmit` gets the values; what the request carries\n * besides them (kastlan's company, keksdose's currency, the `invite_token`) is the\n * app's, as are the role and the associations, which never come from the form (§4.3).\n *\n * **The submit waits for a complete form**: both names (1–120 characters after\n * trimming), a plausible address, a password of at least 8 characters and at most 72\n * bytes, the same password again, the terms ticked, and `appFieldsComplete`. Nothing\n * else is a rule — the strength checklist is advice (keksdose #124), and the kit adds\n * none of its own (§8). So there is never a failed attempt for a missing field, and no\n * field error to show for one.\n *\n * **The address tag** (§4.5) is offered under the email field as one click with the\n * exact result on the button, never applied: sub-addressing is a convention the\n * receiving server may or may not implement, and a silent rewrite would send the\n * verification mail down a path nobody checked. With an invitation the field is fixed\n * to the invited address; the invitee may still take its tagged form, and is told it\n * will be confirmed by a mail of its own (§4.3).\n *\n * **Refusals** are read by code ({@link authErrorCode}): `email_taken` under the email\n * field, which takes the focus; `registration_closed`, `invitation_invalid` and\n * `invitation_expired` above the button; anything else as \"Registration failed\", unless\n * `describeError` has the app's words.\n *\n * Laid out for a 390 px phone: the names sit side by side only where the form is at\n * least 20rem wide (a container query), which the narrow `AuthLayout` card is on a\n * desktop and a phone is not.\n */\nexport function RegisterForm({\n onSubmit,\n emailTag,\n invitedEmail,\n locale: localeProp,\n defaultLocale,\n onLocaleChange,\n languages = ALL_CODES,\n languageField,\n aboveForm,\n underEmail,\n appFields,\n afterFields,\n appFieldsComplete = true,\n termsHref,\n privacyHref,\n signInHref,\n describeError,\n labels: labelsProp,\n className,\n ...rest\n}: RegisterFormProps) {\n const labels = useKitLabels(\"register\", DEFAULT_REGISTER_LABELS, labelsProp);\n const kitLocale = useKitLocale();\n const invited = invitedEmail !== undefined;\n const [firstName, setFirstName] = useState(\"\");\n const [lastName, setLastName] = useState(\"\");\n const [email, setEmail] = useState(invitedEmail ?? \"\");\n const [password, setPassword] = useState(\"\");\n const [confirm, setConfirm] = useState(\"\");\n const [ownLocale, setOwnLocale] = useState<string>(\n () => defaultLocale ?? resolveLanguage([kitLocale, ...browserLanguages()], languages),\n );\n const [accepted, setAccepted] = useState(false);\n const [busy, setBusy] = useState<Busy>(null);\n // `email_taken` belongs to the address it was answered for; another one clears it.\n const [taken, setTaken] = useState<string | null>(null);\n const [failure, setFailure] = useState<ReactNode>(null);\n const emailRef = useRef<HTMLInputElement>(null);\n const tagHintId = useId();\n\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n // What the field shows is what is submitted: the offered code the value resolves to.\n const locale = resolveLanguage([localeProp ?? ownLocale], languages);\n const changeLocale = (code: KitLanguageCode) => {\n if (localeProp === undefined) setOwnLocale(code);\n onLocaleChange?.(code);\n };\n\n const working = busy !== null;\n const suggestion = emailTag ? taggedEmail(email, emailTag) : null;\n // The invitee took the tagged address: offer the way back to the invited one.\n const backToInvited =\n invitedEmail !== undefined && email.trim() !== invitedEmail.trim() ? invitedEmail.trim() : null;\n const canSubmit =\n personNameOk(firstName) &&\n personNameOk(lastName) &&\n emailParts(email) !== null &&\n newPasswordProblem(password, confirm) === null &&\n accepted &&\n appFieldsComplete;\n\n const submit = (e: FormEvent) => {\n e.preventDefault();\n if (!canSubmit || working) return;\n const values: RegisterValues = {\n firstName: firstName.trim(),\n lastName: lastName.trim(),\n email: email.trim(),\n password,\n locale,\n };\n setBusy(\"sending\");\n setFailure(null);\n setTaken(null);\n let result: Promise<unknown>;\n try {\n result = Promise.resolve(onSubmit(values));\n } catch (error) {\n result = Promise.reject(error);\n }\n result.then(\n () => {\n if (mounted.current) setBusy(\"done\");\n },\n (error: unknown) => {\n if (!mounted.current) return;\n setBusy(null);\n const own = describeError?.(error);\n const code = authErrorCode(error);\n if (code === \"email_taken\" && !hasMessage(own)) {\n setTaken(values.email);\n emailRef.current?.focus();\n return;\n }\n setFailure(\n hasMessage(own)\n ? own\n : code === \"registration_closed\"\n ? labels.registrationClosed\n : code === \"invitation_invalid\"\n ? labels.invitationInvalid\n : code === \"invitation_expired\"\n ? labels.invitationExpired\n : labels.failed,\n );\n },\n );\n };\n\n return (\n <div {...rest} className={cn(\"@container space-y-4\", className)}>\n {aboveForm}\n <form className=\"space-y-3\" noValidate onSubmit={submit}>\n <div className=\"grid gap-3 @xs:grid-cols-2\">\n <Input\n name=\"given-name\"\n autoComplete=\"given-name\"\n label={labels.firstName}\n value={firstName}\n onChange={(e) => setFirstName(e.target.value)}\n maxLength={PERSON_NAME_MAX_LENGTH}\n readOnly={working}\n required\n />\n <Input\n name=\"family-name\"\n autoComplete=\"family-name\"\n label={labels.lastName}\n value={lastName}\n onChange={(e) => setLastName(e.target.value)}\n maxLength={PERSON_NAME_MAX_LENGTH}\n readOnly={working}\n required\n />\n </div>\n\n <div>\n <Input\n ref={emailRef}\n type=\"email\"\n name=\"email\"\n autoComplete=\"email\"\n label={labels.email}\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n readOnly={invited || working}\n hint={invited ? labels.invitedEmailHint : undefined}\n error={taken !== null && taken === email.trim() ? labels.emailTaken : undefined}\n required\n />\n {/* The tag, offered rather than applied (§4.5): one click, the exact address\n on the button, reversible by typing — or, invited, by the button back. */}\n {suggestion && (\n <p className=\"mt-1 text-xs text-[var(--text-muted)]\">\n <Button\n type=\"button\"\n variant=\"link\"\n size=\"sm\"\n className=\"h-auto p-0 align-baseline\"\n disabled={working}\n aria-describedby={tagHintId}\n onClick={() => setEmail(suggestion)}\n >\n {labels.emailTagUse(suggestion)}\n </Button>{\" \"}\n <span id={tagHintId}>{labels.emailTagHint}</span>\n </p>\n )}\n {backToInvited !== null && (\n <p className=\"mt-1 text-xs text-[var(--text-muted)]\">\n <span>{labels.invitedTagNote}</span>{\" \"}\n <Button\n type=\"button\"\n variant=\"link\"\n size=\"sm\"\n className=\"h-auto p-0 align-baseline\"\n disabled={working}\n onClick={() => setEmail(backToInvited)}\n >\n {labels.emailTagUse(backToInvited)}\n </Button>\n </p>\n )}\n {underEmail}\n </div>\n\n <NewPasswordFields\n password={password}\n confirm={confirm}\n onPasswordChange={setPassword}\n onConfirmChange={setConfirm}\n busy={working}\n text={{ password: labels.password, confirm: labels.confirmPassword, mismatch: labels.passwordMismatch }}\n />\n\n {languageField === undefined ? (\n <LanguageSelect\n name=\"locale\"\n label={labels.language}\n value={locale}\n codes={languages}\n onChange={changeLocale}\n disabled={working}\n />\n ) : (\n languageField\n )}\n\n {appFields}\n {afterFields}\n\n {/* The kit's terms checkbox (legal contract §3.4). Never an error: an unticked\n box keeps the submit disabled, so there is no failed attempt to explain. */}\n <LegalAcceptCheckbox\n checked={accepted}\n onCheckedChange={setAccepted}\n termsHref={termsHref}\n privacyHref={privacyHref}\n disabled={working}\n />\n\n {hasMessage(failure) && (\n <AlertBanner tone=\"danger\" size=\"sm\" role=\"alert\">\n {failure}\n </AlertBanner>\n )}\n\n <Button type=\"submit\" className=\"w-full\" disabled={!working && !canSubmit} pending={working}>\n {labels.submit}\n </Button>\n </form>\n {signInHref !== undefined && (\n <p className=\"text-center text-sm text-[var(--text-secondary)]\">\n {labels.haveAccount}{\" \"}\n <TextLink href={signInHref} tone=\"primary\">\n {labels.signIn}\n </TextLink>\n </p>\n )}\n </div>\n );\n}\n"],"mappings":";AA0UQ,SACE,KADF;AA1UR,SAAS,WAAW,OAAO,QAAQ,gBAAgB;AAGnD,SAAS,cAAc,oBAAoB;AAC3C,SAAS,eAAe,uBAAuB;AAE/C,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AACpC,SAAS,gBAAgB;AACzB,SAAS,QAAQ,aAAa;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,YAAY,mBAAmB;AACxC,SAAS,oBAAoB,cAAc,8BAA8B;AACzE,SAAS,yBAAyB;AA2D3B,MAAM,0BAA0C;AAAA,EACrD,WAAW;AAAA,EACX,UAAU;AAAA,EACV,OAAO;AAAA,EACP,aAAa,CAAC,YAAY,OAAO,OAAO;AAAA,EACxC,cACE;AAAA,EACF,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,oBAAoB;AAAA,EACpB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,QAAQ;AACV;AAsEA,MAAM,YAAwC,cAAc,IAAI,CAAC,aAAa,SAAS,IAAI;AAG3F,SAAS,mBAAsC;AAC7C,MAAI,OAAO,cAAc,YAAa,QAAO,CAAC;AAC9C,SAAO,UAAU,WAAW,SAAS,UAAU,YAAY,CAAC,UAAU,QAAQ;AAChF;AAqCO,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,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":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/auth/register-form.tsx"],"sourcesContent":["import { useEffect, useId, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, FormEvent, ReactNode } from \"react\";\n\nimport { useKitLabels, useKitLocale } from \"../i18n/kit-labels\";\nimport { KIT_LANGUAGES, resolveLanguage } from \"../i18n/languages\";\nimport type { KitLanguageCode } from \"../i18n/languages\";\nimport { cn } from \"../lib/cn\";\nimport { AlertBanner } from \"../components/alert-banner\";\nimport { hasMessage } from \"../components/choice-parts\";\nimport { LanguageSelect } from \"../components/language-select\";\nimport { LegalAcceptCheckbox } from \"../components/legal-page\";\nimport { TextLink } from \"../components/text-link\";\nimport { Button, Input } from \"../components/ui\";\nimport { authErrorCode, englishRateLimited, isRateLimited, retryAfterSeconds } from \"./auth-errors\";\nimport { emailParts, taggedEmail } from \"./email-tag\";\nimport { newPasswordProblem, personNameOk, PERSON_NAME_MAX_LENGTH } from \"./form-rules\";\nimport { NewPasswordFields } from \"./new-password-fields\";\n\n/** What `RegisterForm` hands `onSubmit` — the core of `POST /auth/register` (§4.2). The\n * app adds its own fields (kastlan's company, keksdose's currency) and the\n * `invite_token` it read from the URL. */\nexport interface RegisterValues {\n /** Trimmed, 1–120 characters. */\n firstName: string;\n /** Trimmed, 1–120 characters. */\n lastName: string;\n /** Trimmed. Lower-casing is the server's (§3.1); a tag is never stripped (§4.5). */\n email: string;\n /** As typed: at least 8 characters, at most 72 bytes. */\n password: string;\n /** The language picked — one of `languages` — for every mail to the user (§3.1). */\n locale: KitLanguageCode;\n}\n\n/**\n * Every string `RegisterForm` renders — the `register` namespace of `<UiKitProvider\n * labels>`, overridable per instance through `labels`. keksdose's words where it has\n * them. The terms checkbox speaks `legal.accept`, the strength meter `passwordStrength`.\n */\nexport interface RegisterLabels {\n firstName: string;\n lastName: string;\n email: string;\n /** The address-tag button (§4.5), given the exact address it would use — and, with an\n * invitation, the button back to the invited address. */\n emailTagUse: (address: string) => string;\n /** The line after the address-tag button. */\n emailTagHint: string;\n /** Under an invited (read-only) email field. */\n invitedEmailHint: string;\n /** Once the invitee took the tagged address: it is not the invited one, so it is\n * confirmed by a mail of its own (§4.3). */\n invitedTagNote: string;\n password: string;\n confirmPassword: string;\n passwordMismatch: string;\n language: string;\n /** The submit button. */\n submit: string;\n /** Before the link to `signInHref`. */\n haveAccount: string;\n /** The link to `signInHref`. */\n signIn: string;\n /** `email_taken`, under the email field. */\n emailTaken: string;\n /** `registration_closed` — the gate refused the address (§4.3). */\n registrationClosed: string;\n /** `invitation_invalid` — the invitation link is unknown or spent. */\n invitationInvalid: string;\n /** `invitation_expired`. */\n invitationExpired: string;\n /** Any other failure. */\n failed: string;\n /** 0.30.0: the request was throttled — HTTP 429 ({@link isRateLimited}) — given the\n * `Retry-After` wait in seconds, or `undefined` without one. OPTIONAL, like every key\n * added to a shipped interface (an annotated call site must keep compiling); the\n * provider's `register`, then English, fill it. */\n rateLimited?: (seconds?: number) => string;\n}\n\n/** `Required`: every key, the 0.30 one included, has its English here. */\nexport const DEFAULT_REGISTER_LABELS: Required<RegisterLabels> = {\n firstName: \"First name\",\n lastName: \"Last name\",\n email: \"Email\",\n emailTagUse: (address) => `Use ${address}`,\n emailTagHint:\n \"Many providers deliver name+tag@… to the same inbox, so mail from this app is easy to filter and trace. Check yours does before you rely on it: you would sign in with the tagged address.\",\n invitedEmailHint: \"The address your invitation was sent to.\",\n invitedTagNote: \"The tagged address gets a confirmation mail of its own.\",\n password: \"Password\",\n confirmPassword: \"Repeat password\",\n passwordMismatch: \"The passwords don't match.\",\n language: \"Language\",\n submit: \"Create account\",\n haveAccount: \"Already have an account?\",\n signIn: \"Sign in\",\n emailTaken: \"An account with this email address already exists.\",\n registrationClosed: \"New accounts are by invitation only. Ask the operator to invite your email address.\",\n invitationInvalid: \"This invitation link is not valid.\",\n invitationExpired: \"This invitation has expired. Ask for a new one.\",\n failed: \"Registration failed. Please try again.\",\n rateLimited: englishRateLimited,\n};\n\nexport interface RegisterFormProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"onSubmit\" | \"children\"> {\n /**\n * The form was submitted with everything filled in. Send it (`POST /auth/register`,\n * §4.2) and resolve once the user is signed in, or reject with the client's error:\n * `email_taken` shows under the email field, `registration_closed` and the\n * invitation codes above the button, anything else as \"Registration failed\". The form\n * never sends a request itself (§8): keksdose must see the password on its way.\n *\n * On resolve the form stays busy while the app navigates.\n */\n onSubmit: (values: RegisterValues) => Promise<unknown>;\n /**\n * The app's address tag (`\"kastlan\"`, §4.5). Once the email is plausible, a button\n * under it offers the tagged address — \"Use ada+kastlan@example.com\" — with a line on\n * why; one click puts it in the field. Never applied on its own. Left out, no offer.\n */\n emailTag?: string;\n /**\n * The address of the invitation this sign-up comes from (§4.4): the field starts with\n * it and is read-only. With `emailTag`, the invitee may still take the tagged form of\n * it — the server accepts exactly that variant — and go back.\n */\n invitedEmail?: string;\n /**\n * 0.29.1: an address to start with that stays EDITABLE, with the `+tag` suggestion still\n * offered — for a link anyone can build (keksdose's token-free `/register?email=…`\n * beta link, kept while an app moves to invitations). Unlike `invitedEmail` it proves\n * nothing, so it locks nothing. `invitedEmail` wins when both are given.\n */\n defaultEmail?: string;\n /**\n * The language field's value — controlled. Pass the app's UI language\n * (`i18n.resolvedLanguage`) with `onLocaleChange` switching it, and the field IS the\n * app's language switch, with no copy of its own to drift from a second switcher on\n * the page (keksdose's register page has one in its header). Any tag; it shows (and\n * submits) the offered code it resolves to. Left out, the form keeps its own, starting\n * from `defaultLocale`, else the provider's language, else the browser's.\n */\n locale?: string;\n /** The uncontrolled language field's start value. */\n defaultLocale?: string;\n /** A language was picked. */\n onLocaleChange?: (code: KitLanguageCode) => void;\n /** The languages to offer, in order. Default all seven. */\n languages?: readonly KitLanguageCode[];\n /**\n * The app's own language field in place of the kit's select — keksdose's\n * `LanguageSetting` bound to its i18n. `null` draws none (an app with one language);\n * the submitted `locale` is then `locale`'s.\n */\n languageField?: ReactNode;\n /** Above the form — keksdose's closed-beta banner. */\n aboveForm?: ReactNode;\n /** Under the email field and its tag offer — an app's own hint. */\n underEmail?: ReactNode;\n /** The app's sign-up fields (§4.1 item 7): kastlan's Company, keksdose's reporting\n * currency. Their values are the app's; say whether they are complete with\n * `appFieldsComplete`. */\n appFields?: ReactNode;\n /** After the app fields, before the terms — keksdose's privacy-mode note. */\n afterFields?: ReactNode;\n /** Whether the app fields are filled in as required — kastlan's Company without an\n * invitation. The submit waits for it. Default `true`. */\n appFieldsComplete?: boolean;\n /** The terms checkbox's links. Default `/terms` and `/privacy`. */\n termsHref?: string;\n privacyHref?: string;\n /** \"Already have an account? Sign in\" goes here — `/login`. Left out, no line. */\n signInHref?: string;\n /** The app's own words for a failure the kit cannot know (the device offline, a\n * throttle with its wait), or `undefined` for the kit's. Asked first, for every\n * failure; a bare `429` needs none since 0.30.0 — the kit says `rateLimited`. */\n describeError?: (error: unknown) => ReactNode | undefined;\n labels?: Partial<RegisterLabels>;\n}\n\nconst ALL_CODES: readonly KitLanguageCode[] = KIT_LANGUAGES.map((language) => language.code);\n\n/** The browser's languages, in its order — absent outside a browser. */\nfunction browserLanguages(): readonly string[] {\n if (typeof navigator === \"undefined\") return [];\n return navigator.languages?.length ? navigator.languages : [navigator.language];\n}\n\ntype Busy = \"sending\" | \"done\" | null;\n\n/**\n * Sign-up for every app (docs/auth-harmonization.md §4.1, §8): first and last name,\n * email with the address-tag offer, password with the strength meter and its\n * confirmation, language, the app's own fields in a slot, and the terms. keksdose's\n * `RegisterPage` (features/auth/register-page.tsx) with its slots made props.\n *\n * **It never sends a request.** `onSubmit` gets the values; what the request carries\n * besides them (kastlan's company, keksdose's currency, the `invite_token`) is the\n * app's, as are the role and the associations, which never come from the form (§4.3).\n *\n * **The submit waits for a complete form**: both names (1–120 characters after\n * trimming), a plausible address, a password of at least 8 characters and at most 72\n * bytes, the same password again, the terms ticked, and `appFieldsComplete`. Nothing\n * else is a rule — the strength checklist is advice (keksdose #124), and the kit adds\n * none of its own (§8). So there is never a failed attempt for a missing field, and no\n * field error to show for one.\n *\n * **The address tag** (§4.5) is offered under the email field as one click with the\n * exact result on the button, never applied: sub-addressing is a convention the\n * receiving server may or may not implement, and a silent rewrite would send the\n * verification mail down a path nobody checked. With an invitation the field is fixed\n * to the invited address; the invitee may still take its tagged form, and is told it\n * will be confirmed by a mail of its own (§4.3).\n *\n * **Refusals** are read by code ({@link authErrorCode}): `email_taken` under the email\n * field, which takes the focus; `registration_closed`, `invitation_invalid` and\n * `invitation_expired` above the button; anything else as \"Registration failed\", unless\n * `describeError` has the app's words.\n *\n * Laid out for a 390 px phone: the names sit side by side only where the form is at\n * least 20rem wide (a container query), which the narrow `AuthLayout` card is on a\n * desktop and a phone is not.\n */\nexport function RegisterForm({\n onSubmit,\n emailTag,\n invitedEmail,\n defaultEmail,\n locale: localeProp,\n defaultLocale,\n onLocaleChange,\n languages = ALL_CODES,\n languageField,\n aboveForm,\n underEmail,\n appFields,\n afterFields,\n appFieldsComplete = true,\n termsHref,\n privacyHref,\n signInHref,\n describeError,\n labels: labelsProp,\n className,\n ...rest\n}: RegisterFormProps) {\n const labels = useKitLabels(\"register\", DEFAULT_REGISTER_LABELS, labelsProp);\n const kitLocale = useKitLocale();\n const invited = invitedEmail !== undefined;\n const [firstName, setFirstName] = useState(\"\");\n const [lastName, setLastName] = useState(\"\");\n const [email, setEmail] = useState(invitedEmail ?? defaultEmail ?? \"\");\n const [password, setPassword] = useState(\"\");\n const [confirm, setConfirm] = useState(\"\");\n const [ownLocale, setOwnLocale] = useState<string>(\n () => defaultLocale ?? resolveLanguage([kitLocale, ...browserLanguages()], languages),\n );\n const [accepted, setAccepted] = useState(false);\n const [busy, setBusy] = useState<Busy>(null);\n // `email_taken` belongs to the address it was answered for; another one clears it.\n const [taken, setTaken] = useState<string | null>(null);\n const [failure, setFailure] = useState<ReactNode>(null);\n const emailRef = useRef<HTMLInputElement>(null);\n const tagHintId = useId();\n\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n // What the field shows is what is submitted: the offered code the value resolves to.\n const locale = resolveLanguage([localeProp ?? ownLocale], languages);\n const changeLocale = (code: KitLanguageCode) => {\n if (localeProp === undefined) setOwnLocale(code);\n onLocaleChange?.(code);\n };\n\n const working = busy !== null;\n const suggestion = emailTag ? taggedEmail(email, emailTag) : null;\n // The invitee took the tagged address: offer the way back to the invited one.\n const backToInvited =\n invitedEmail !== undefined && email.trim() !== invitedEmail.trim() ? invitedEmail.trim() : null;\n const canSubmit =\n personNameOk(firstName) &&\n personNameOk(lastName) &&\n emailParts(email) !== null &&\n newPasswordProblem(password, confirm) === null &&\n accepted &&\n appFieldsComplete;\n\n const submit = (e: FormEvent) => {\n e.preventDefault();\n if (!canSubmit || working) return;\n const values: RegisterValues = {\n firstName: firstName.trim(),\n lastName: lastName.trim(),\n email: email.trim(),\n password,\n locale,\n };\n setBusy(\"sending\");\n setFailure(null);\n setTaken(null);\n let result: Promise<unknown>;\n try {\n result = Promise.resolve(onSubmit(values));\n } catch (error) {\n result = Promise.reject(error);\n }\n result.then(\n () => {\n if (mounted.current) setBusy(\"done\");\n },\n (error: unknown) => {\n if (!mounted.current) return;\n setBusy(null);\n const own = describeError?.(error);\n const code = authErrorCode(error);\n if (code === \"email_taken\" && !hasMessage(own)) {\n setTaken(values.email);\n emailRef.current?.focus();\n return;\n }\n setFailure(\n hasMessage(own)\n ? own\n : isRateLimited(error)\n ? (labels.rateLimited ?? DEFAULT_REGISTER_LABELS.rateLimited)(retryAfterSeconds(error))\n : code === \"registration_closed\"\n ? labels.registrationClosed\n : code === \"invitation_invalid\"\n ? labels.invitationInvalid\n : code === \"invitation_expired\"\n ? labels.invitationExpired\n : labels.failed,\n );\n },\n );\n };\n\n return (\n <div {...rest} className={cn(\"@container space-y-4\", className)}>\n {aboveForm}\n <form className=\"space-y-3\" noValidate onSubmit={submit}>\n <div className=\"grid gap-3 @xs:grid-cols-2\">\n <Input\n name=\"given-name\"\n autoComplete=\"given-name\"\n label={labels.firstName}\n value={firstName}\n onChange={(e) => setFirstName(e.target.value)}\n maxLength={PERSON_NAME_MAX_LENGTH}\n readOnly={working}\n required\n />\n <Input\n name=\"family-name\"\n autoComplete=\"family-name\"\n label={labels.lastName}\n value={lastName}\n onChange={(e) => setLastName(e.target.value)}\n maxLength={PERSON_NAME_MAX_LENGTH}\n readOnly={working}\n required\n />\n </div>\n\n <div>\n <Input\n ref={emailRef}\n type=\"email\"\n name=\"email\"\n autoComplete=\"email\"\n label={labels.email}\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n readOnly={invited || working}\n hint={invited ? labels.invitedEmailHint : undefined}\n error={taken !== null && taken === email.trim() ? labels.emailTaken : undefined}\n required\n />\n {/* The tag, offered rather than applied (§4.5): one click, the exact address\n on the button, reversible by typing — or, invited, by the button back. */}\n {suggestion && (\n <p className=\"mt-1 text-xs text-[var(--text-muted)]\">\n <Button\n type=\"button\"\n variant=\"link\"\n size=\"sm\"\n className=\"h-auto p-0 align-baseline\"\n disabled={working}\n aria-describedby={tagHintId}\n onClick={() => setEmail(suggestion)}\n >\n {labels.emailTagUse(suggestion)}\n </Button>{\" \"}\n <span id={tagHintId}>{labels.emailTagHint}</span>\n </p>\n )}\n {backToInvited !== null && (\n <p className=\"mt-1 text-xs text-[var(--text-muted)]\">\n <span>{labels.invitedTagNote}</span>{\" \"}\n <Button\n type=\"button\"\n variant=\"link\"\n size=\"sm\"\n className=\"h-auto p-0 align-baseline\"\n disabled={working}\n onClick={() => setEmail(backToInvited)}\n >\n {labels.emailTagUse(backToInvited)}\n </Button>\n </p>\n )}\n {underEmail}\n </div>\n\n <NewPasswordFields\n password={password}\n confirm={confirm}\n onPasswordChange={setPassword}\n onConfirmChange={setConfirm}\n busy={working}\n text={{ password: labels.password, confirm: labels.confirmPassword, mismatch: labels.passwordMismatch }}\n />\n\n {languageField === undefined ? (\n <LanguageSelect\n name=\"locale\"\n label={labels.language}\n value={locale}\n codes={languages}\n onChange={changeLocale}\n disabled={working}\n />\n ) : (\n languageField\n )}\n\n {appFields}\n {afterFields}\n\n {/* The kit's terms checkbox (legal contract §3.4). Never an error: an unticked\n box keeps the submit disabled, so there is no failed attempt to explain. */}\n <LegalAcceptCheckbox\n checked={accepted}\n onCheckedChange={setAccepted}\n termsHref={termsHref}\n privacyHref={privacyHref}\n disabled={working}\n />\n\n {hasMessage(failure) && (\n <AlertBanner tone=\"danger\" size=\"sm\" role=\"alert\">\n {failure}\n </AlertBanner>\n )}\n\n <Button type=\"submit\" className=\"w-full\" disabled={!working && !canSubmit} pending={working}>\n {labels.submit}\n </Button>\n </form>\n {signInHref !== undefined && (\n <p className=\"text-center text-sm text-[var(--text-secondary)]\">\n {labels.haveAccount}{\" \"}\n <TextLink href={signInHref} tone=\"primary\">\n {labels.signIn}\n </TextLink>\n </p>\n )}\n </div>\n );\n}\n"],"mappings":";AA4VQ,SACE,KADF;AA5VR,SAAS,WAAW,OAAO,QAAQ,gBAAgB;AAGnD,SAAS,cAAc,oBAAoB;AAC3C,SAAS,eAAe,uBAAuB;AAE/C,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AACpC,SAAS,gBAAgB;AACzB,SAAS,QAAQ,aAAa;AAC9B,SAAS,eAAe,oBAAoB,eAAe,yBAAyB;AACpF,SAAS,YAAY,mBAAmB;AACxC,SAAS,oBAAoB,cAAc,8BAA8B;AACzE,SAAS,yBAAyB;AAiE3B,MAAM,0BAAoD;AAAA,EAC/D,WAAW;AAAA,EACX,UAAU;AAAA,EACV,OAAO;AAAA,EACP,aAAa,CAAC,YAAY,OAAO,OAAO;AAAA,EACxC,cACE;AAAA,EACF,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,QAAQ;A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,UACV,UAAU;AAAA;AAAA,MACZ,IAEA;AAAA,MAGD;AAAA,MACA;AAAA,MAID;AAAA,QAAC;AAAA;AAAA,UACC,SAAS;AAAA,UACT,iBAAiB;AAAA,UACjB;AAAA,UACA;AAAA,UACA,UAAU;AAAA;AAAA,MACZ;AAAA,MAEC,WAAW,OAAO,KACjB,oBAAC,eAAY,MAAK,UAAS,MAAK,MAAK,MAAK,SACvC,mBACH;AAAA,MAGF,oBAAC,UAAO,MAAK,UAAS,WAAU,UAAS,UAAU,CAAC,WAAW,CAAC,WAAW,SAAS,SACjF,iBAAO,QACV;AAAA,OACF;AAAA,IACC,eAAe,UACd,qBAAC,OAAE,WAAU,oDACV;AAAA,aAAO;AAAA,MAAa;AAAA,MACrB,oBAAC,YAAS,MAAM,YAAY,MAAK,WAC9B,iBAAO,QACV;AAAA,OACF;AAAA,KAEJ;AAEJ;","names":[]}
|
|
@@ -33,8 +33,14 @@ interface ResetPasswordLabels {
|
|
|
33
33
|
sessionsEnded: string;
|
|
34
34
|
/** The button out — to sign-in, with the address filled in. */
|
|
35
35
|
signIn: string;
|
|
36
|
+
/** 0.30.0: the save was throttled — HTTP 429 ({@link isRateLimited}) — given the
|
|
37
|
+
* `Retry-After` wait in seconds, or `undefined` without one. OPTIONAL, like every key
|
|
38
|
+
* added to a shipped interface; the provider's `resetPassword`, then English, fill
|
|
39
|
+
* it. */
|
|
40
|
+
rateLimited?: (seconds?: number) => string;
|
|
36
41
|
}
|
|
37
|
-
|
|
42
|
+
/** `Required`: every key, the 0.30 one included, has its English here. */
|
|
43
|
+
declare const DEFAULT_RESET_PASSWORD_LABELS: Required<ResetPasswordLabels>;
|
|
38
44
|
/** What `onCheck` may resolve with — keksdose's `/password-reset/check` answer. */
|
|
39
45
|
interface ResetPasswordCheck {
|
|
40
46
|
/** The account's address: named over the fields ("You're setting a new password for
|
|
@@ -86,8 +92,9 @@ interface ResetPasswordFormProps extends Omit<ComponentPropsWithoutRef<"div">, "
|
|
|
86
92
|
/** "Request a new link" — the app's "Forgot password" page. Default
|
|
87
93
|
* `/forgot-password`. */
|
|
88
94
|
forgotHref?: string;
|
|
89
|
-
/** The app's words for a failed save (
|
|
90
|
-
*
|
|
95
|
+
/** The app's words for a failed save (the device offline), or `undefined` for the
|
|
96
|
+
* kit's: `rateLimited` for a bare `429` (0.30.0), else `failed`. Not asked for
|
|
97
|
+
* `token_invalid`, which is a state. */
|
|
91
98
|
describeError?: (error: unknown) => ReactNode | undefined;
|
|
92
99
|
/** The heading. Default `labels.title`; `null` draws none, for a page that puts it
|
|
93
100
|
* in `AuthLayout`'s `title` instead. */
|
|
@@ -7,7 +7,7 @@ import { useKitLabels } from "../i18n/kit-labels.js";
|
|
|
7
7
|
import { AlertBanner } from "../components/alert-banner.js";
|
|
8
8
|
import { LoadingState } from "../components/loading-state.js";
|
|
9
9
|
import { Button, EmptyState } from "../components/ui.js";
|
|
10
|
-
import { authErrorCode } from "./auth-errors.js";
|
|
10
|
+
import { authErrorCode, englishRateLimited, isRateLimited, retryAfterSeconds } from "./auth-errors.js";
|
|
11
11
|
import { newPasswordProblem } from "./form-rules.js";
|
|
12
12
|
import { NewPasswordFields } from "./new-password-fields.js";
|
|
13
13
|
import {
|
|
@@ -34,7 +34,8 @@ const DEFAULT_RESET_PASSWORD_LABELS = {
|
|
|
34
34
|
requestNew: "Request a new link",
|
|
35
35
|
success: "Your password has been changed. You can sign in with it now.",
|
|
36
36
|
sessionsEnded: "Signed-in devices were signed out \u2014 you\u2019ll need to sign in again there.",
|
|
37
|
-
signIn: "Go to sign in"
|
|
37
|
+
signIn: "Go to sign in",
|
|
38
|
+
rateLimited: englishRateLimited
|
|
38
39
|
};
|
|
39
40
|
function ResetPasswordForm({
|
|
40
41
|
token,
|
|
@@ -129,7 +130,9 @@ function ResetPasswordForm({
|
|
|
129
130
|
setPhase({ token, phase: { kind: "invalid" } });
|
|
130
131
|
return;
|
|
131
132
|
}
|
|
132
|
-
setFailure(
|
|
133
|
+
setFailure(
|
|
134
|
+
describeError?.(error) ?? (isRateLimited(error) ? (labels.rateLimited ?? DEFAULT_RESET_PASSWORD_LABELS.rateLimited)(retryAfterSeconds(error)) : labels.failed)
|
|
135
|
+
);
|
|
133
136
|
}
|
|
134
137
|
);
|
|
135
138
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/reset-password-form.tsx"],"sourcesContent":["import { useEffect, useId, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, FormEvent, ReactNode } from \"react\";\nimport { CheckCircle2, XCircle } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { AlertBanner } from \"../components/alert-banner\";\nimport { LoadingState } from \"../components/loading-state\";\nimport { Button, EmptyState } from \"../components/ui\";\nimport { authErrorCode } from \"./auth-errors\";\nimport { newPasswordProblem } from \"./form-rules\";\nimport { NewPasswordFields } from \"./new-password-fields\";\nimport {\n FORM_HEADING_CLASS,\n INTRO_CLASS,\n OUTCOME_CLASS,\n OutcomeMessage,\n useFocusWhen,\n useOncePerKey,\n withQuery,\n} from \"./status-parts\";\nimport type { AuthHeadingLevel } from \"./status-parts\";\n\n/* ── Labels ──────────────────────────────────────────────────────────────── */\n\n/** Every string the form renders — the `resetPassword` namespace. keksdose's words\n * (`auth.reset.*`), which kastlan took over. */\nexport interface ResetPasswordLabels {\n /** The heading, on every state. */\n title: string;\n /** While the link is checked. */\n checking: string;\n /** Over the fields, given the account's address (when the check returned one). */\n intro: (email: string) => string;\n newPassword: string;\n confirmPassword: string;\n /** Under the confirmation while it differs. */\n mismatch: string;\n submit: string;\n /** The new password was not saved, for a reason that is not the link. */\n failed: string;\n /** The page was opened without a `token`. */\n noToken: string;\n /** The link is unknown, spent or expired — one sentence, as the server gives one\n * code (`token_invalid`). */\n invalid: string;\n /** Under it. */\n invalidHint: string;\n /** The way forward from an invalid link: back to \"Forgot password\". */\n requestNew: string;\n /** Done. */\n success: string;\n /** Under it: a reset ends every session (§6.3). */\n sessionsEnded: string;\n /** The button out — to sign-in, with the address filled in. */\n signIn: string;\n}\n\nexport const DEFAULT_RESET_PASSWORD_LABELS: ResetPasswordLabels = {\n title: \"Choose a new password\",\n checking: \"Checking the link…\",\n intro: (email) => `You’re setting a new password for ${email}.`,\n newPassword: \"New password\",\n confirmPassword: \"Repeat new password\",\n mismatch: \"The passwords don’t match.\",\n submit: \"Save password\",\n failed: \"The password could not be changed.\",\n noToken: \"This link is incomplete.\",\n invalid: \"This link is invalid or has expired.\",\n invalidHint: \"Links are valid for one hour and work only once. Just request a new one.\",\n requestNew: \"Request a new link\",\n success: \"Your password has been changed. You can sign in with it now.\",\n sessionsEnded: \"Signed-in devices were signed out — you’ll need to sign in again there.\",\n signIn: \"Go to sign in\",\n};\n\n/* ── Types ───────────────────────────────────────────────────────────────── */\n\n/** What `onCheck` may resolve with — keksdose's `/password-reset/check` answer. */\nexport interface ResetPasswordCheck {\n /** The account's address: named over the fields (\"You're setting a new password for\n * …\") and handed to the password manager, which files the new password under it. */\n email?: string;\n /** The app's notices over the fields, shown BEFORE the password is typed — keksdose's\n * \"your account is end-to-end encrypted: this restores your sign-in, not your data\". */\n notices?: ReactNode;\n}\n\n/** What `onSubmit` hands over. */\nexport interface ResetPasswordValues {\n token: string;\n password: string;\n}\n\n/** What `onSubmit` resolves with — keksdose's `/password-reset/confirm` answer, which\n * carries no tokens (§6.3). */\nexport interface ResetPasswordResult {\n /** The account's address — the sign-in it leads to is filled in with it. */\n email: string;\n /** The app's outcomes, shown on the done state: keksdose's recovery-code notice for an\n * encrypted account, \"Your 2 personal access tokens were revoked\". */\n notices?: ReactNode;\n}\n\ntype Phase =\n | { kind: \"form\"; check: ResetPasswordCheck }\n | { kind: \"invalid\" }\n | { kind: \"done\"; result: ResetPasswordResult };\n\nexport interface ResetPasswordFormProps\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onSubmit\" | \"children\" | \"title\"> {\n /** The link's token — the app's `?token=` (keksdose, kastlan: `/reset-password?token=…`).\n * Empty: the link was cut short, and the page says so without asking anyone. */\n token: string;\n /**\n * Check the link before the form shows (`/auth/password-reset/check`) — once per\n * token, on mount. Checking does not use it up, so a reload is free. Resolve (with\n * the address and any notices) for a live link; reject for a dead one, and the page\n * says \"This link is invalid or has expired\" with the way to a new one.\n */\n onCheck: (token: string) => Promise<ResetPasswordCheck | void | undefined>;\n /**\n * The new password was submitted: send `/auth/password-reset/confirm`. Resolve with\n * the account's address (and the app's notices) — no tokens: a reset is not a sign-in\n * (§6.3). Reject with the client's error: `token_invalid` (the link expired or was\n * used in another tab while the form was open) goes to the invalid state; anything\n * else stays on the form with the password kept.\n */\n onSubmit: (values: ResetPasswordValues) => Promise<ResetPasswordResult>;\n /** \"Go to sign in\" calls this with the address, for an app that routes in code.\n * Without it, the button is a link to `signInHref`. */\n onSignIn?: (email: string) => void;\n /** Where \"Go to sign in\" leads, with `?email=` added — read it into `SignInForm`'s\n * `defaultEmail`. Default `/login`. */\n signInHref?: string;\n /** \"Request a new link\" — the app's \"Forgot password\" page. Default\n * `/forgot-password`. */\n forgotHref?: string;\n /** The app's words for a failed save (a `429`, the device offline), or `undefined`\n * for the kit's `failed`. Not asked for `token_invalid`, which is a state. */\n describeError?: (error: unknown) => ReactNode | undefined;\n /** The heading. Default `labels.title`; `null` draws none, for a page that puts it\n * in `AuthLayout`'s `title` instead. */\n title?: ReactNode;\n /** The heading's level. Default `h2`, under the page's `h1`. */\n headingAs?: AuthHeadingLevel;\n labels?: Partial<ResetPasswordLabels>;\n}\n\n/**\n * Redeem a password-reset link (`/reset-password?token=…`, docs/auth-harmonization.md\n * §6.3, §7) — keksdose's `ResetPasswordPage` (features/auth/reset-password-page.tsx),\n * which kastlan built its own on.\n *\n * **The link is checked first** (`onCheck`), and only then does the form appear: an\n * expired link should say so before someone types a new password twice, not after.\n *\n * **A reset is not a sign-in** (§6.3, §10.11). The confirm answers without tokens, so a\n * 2FA account cannot skip its second factor by way of its inbox, and the page ends on\n * \"Go to sign in\" with the address filled in — the person has just typed the new\n * password twice; signing in is one step. What else the reset did is said there:\n * every other session ended (the kit's line, true in all three apps), and the app's own\n * outcomes in `notices` — keksdose's recovery-code notice and its revoked API tokens.\n *\n * **The password** is chosen with the same fields as `RegisterForm` and `SignInForm`'s\n * set-password step ({@link NewPasswordFields}): the strength meter and its checklist as\n * advice, and only the two hard rules — at least 8 characters, at most 72 bytes (§8).\n * The submit waits for both and a matching confirmation.\n *\n * The form never sends a request itself (§8): the token and the password go to the\n * callbacks, and the page renders what they resolve with.\n */\nexport function ResetPasswordForm({\n token,\n onCheck,\n onSubmit,\n onSignIn,\n signInHref = \"/login\",\n forgotHref = \"/forgot-password\",\n describeError,\n title,\n headingAs: Heading = \"h2\",\n labels: labelsProp,\n className,\n ...rest\n}: ResetPasswordFormProps) {\n const labels = useKitLabels(\"resetPassword\", DEFAULT_RESET_PASSWORD_LABELS, labelsProp);\n // The phase belongs to the token it was reached with: a new token starts over at the\n // check without a reset effect.\n const [phase, setPhase] = useState<{ token: string; phase: Phase } | null>(null);\n const current: Phase | \"checking\" =\n token === \"\" ? { kind: \"invalid\" } : phase?.token === token ? phase.phase : \"checking\";\n\n useOncePerKey(token === \"\" ? null : token, onCheck, (key, result) =>\n setPhase({\n token: key,\n phase: result.ok ? { kind: \"form\", check: result.value ?? {} } : { kind: \"invalid\" },\n }),\n );\n\n const [password, setPassword] = useState(\"\");\n const [confirm, setConfirm] = useState(\"\");\n const [pending, setPending] = useState(false);\n const [failure, setFailure] = useState<ReactNode>(null);\n const headingId = useId();\n const passwordRef = useRef<HTMLInputElement>(null);\n const doneRef = useRef<HTMLDivElement>(null);\n const kind = current === \"checking\" ? \"checking\" : current.kind;\n\n // The form arrives after the check: the field is where the person is going.\n useEffect(() => {\n if (kind === \"form\") passwordRef.current?.focus();\n }, [kind]);\n useFocusWhen(kind === \"done\", doneRef);\n\n const heading =\n title === null ? null : (\n <Heading id={headingId} className={FORM_HEADING_CLASS}>\n {title ?? labels.title}\n </Heading>\n );\n const rootClass = cn(\"space-y-3\", className);\n\n if (current === \"checking\") {\n return (\n <div {...rest} data-state=\"checking\" aria-busy className={rootClass}>\n {heading}\n <LoadingState size=\"sm\" label={labels.checking} />\n </div>\n );\n }\n\n if (current.kind === \"invalid\") {\n return (\n <div {...rest} data-state=\"invalid\" className={rootClass}>\n {heading}\n <EmptyState\n tone=\"danger\"\n icon={<XCircle />}\n title={token === \"\" ? labels.noToken : labels.invalid}\n hint={labels.invalidHint}\n action={\n <Button href={forgotHref} variant=\"brand\">\n {labels.requestNew}\n </Button>\n }\n className={OUTCOME_CLASS}\n />\n </div>\n );\n }\n\n if (current.kind === \"done\") {\n const { email, notices } = current.result;\n return (\n <div {...rest} data-state=\"done\" className={rootClass}>\n {heading}\n <OutcomeMessage icon={<CheckCircle2 className=\"text-[var(--success)]\" />} focusRef={doneRef}>\n <p className={INTRO_CLASS}>{labels.success}</p>\n </OutcomeMessage>\n {notices}\n <p className=\"text-xs text-[var(--text-muted)]\">{labels.sessionsEnded}</p>\n {onSignIn ? (\n <Button type=\"button\" variant=\"brand\" className=\"w-full\" onClick={() => onSignIn(email)}>\n {labels.signIn}\n </Button>\n ) : (\n <Button href={email ? withQuery(signInHref, \"email\", email) : signInHref} variant=\"brand\" className=\"w-full\">\n {labels.signIn}\n </Button>\n )}\n </div>\n );\n }\n\n const { email, notices } = current.check;\n const problem = newPasswordProblem(password, confirm);\n\n const submit = (e: FormEvent) => {\n e.preventDefault();\n if (pending || problem !== null) return;\n setFailure(null);\n setPending(true);\n Promise.resolve()\n .then(() => onSubmit({ token, password }))\n .then(\n (result) => {\n setPending(false);\n setPassword(\"\");\n setConfirm(\"\");\n setPhase({ token, phase: { kind: \"done\", result } });\n },\n (error: unknown) => {\n setPending(false);\n if (authErrorCode(error) === \"token_invalid\") {\n setPassword(\"\");\n setConfirm(\"\");\n setPhase({ token, phase: { kind: \"invalid\" } });\n return;\n }\n setFailure(describeError?.(error) ?? labels.failed);\n },\n );\n };\n\n return (\n <div {...rest} data-state=\"form\" className={rootClass}>\n <form className=\"space-y-3\" aria-labelledby={title === null ? undefined : headingId} onSubmit={submit}>\n {heading}\n {email ? <p className={INTRO_CLASS}>{labels.intro(email)}</p> : null}\n {notices}\n {/* Which account the new password is for, for the password manager: it files\n the new password under this username instead of guessing (kastlan). */}\n {email ? <input type=\"email\" name=\"username\" autoComplete=\"username\" value={email} readOnly hidden /> : null}\n <NewPasswordFields\n password={password}\n confirm={confirm}\n onPasswordChange={(next) => {\n setPassword(next);\n if (failure) setFailure(null);\n }}\n onConfirmChange={setConfirm}\n busy={pending}\n passwordRef={passwordRef}\n text={{ password: labels.newPassword, confirm: labels.confirmPassword, mismatch: labels.mismatch }}\n />\n {failure != null && (\n <AlertBanner tone=\"danger\" size=\"sm\" role=\"alert\">\n {failure}\n </AlertBanner>\n )}\n <Button type=\"submit\" className=\"w-full\" disabled={!pending && problem !== null} pending={pending}>\n {labels.submit}\n </Button>\n </form>\n </div>\n );\n}\n"],"mappings":";AAwNM,cAQA,YARA;AAxNN,SAAS,WAAW,OAAO,QAAQ,gBAAgB;AAEnD,SAAS,cAAc,eAAe;AACtC,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,kBAAkB;AACnC,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAsCA,MAAM,gCAAqD;AAAA,EAChE,OAAO;AAAA,EACP,UAAU;AAAA,EACV,OAAO,CAAC,UAAU,0CAAqC,KAAK;AAAA,EAC5D,aAAa;AAAA,EACb,iBAAiB;AAAA,EACjB,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,aAAa;AAAA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,EAAE,UAAU,OAAO,aAAa,SAAS,OAAO,iBAAiB,UAAU,OAAO,SAAS;AAAA;AAAA,IACnG;AAAA,IACC,WAAW,QACV,oBAAC,eAAY,MAAK,UAAS,MAAK,MAAK,MAAK,SACvC,mBACH;AAAA,IAEF,oBAAC,UAAO,MAAK,UAAS,WAAU,UAAS,UAAU,CAAC,WAAW,YAAY,MAAM,SAC9E,iBAAO,QACV;AAAA,KACF,GACF;AAEJ;","names":["email","notices"]}
|
|
1
|
+
{"version":3,"sources":["../../src/auth/reset-password-form.tsx"],"sourcesContent":["import { useEffect, useId, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, FormEvent, ReactNode } from \"react\";\nimport { CheckCircle2, XCircle } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { AlertBanner } from \"../components/alert-banner\";\nimport { LoadingState } from \"../components/loading-state\";\nimport { Button, EmptyState } from \"../components/ui\";\nimport { authErrorCode, englishRateLimited, isRateLimited, retryAfterSeconds } from \"./auth-errors\";\nimport { newPasswordProblem } from \"./form-rules\";\nimport { NewPasswordFields } from \"./new-password-fields\";\nimport {\n FORM_HEADING_CLASS,\n INTRO_CLASS,\n OUTCOME_CLASS,\n OutcomeMessage,\n useFocusWhen,\n useOncePerKey,\n withQuery,\n} from \"./status-parts\";\nimport type { AuthHeadingLevel } from \"./status-parts\";\n\n/* ── Labels ──────────────────────────────────────────────────────────────── */\n\n/** Every string the form renders — the `resetPassword` namespace. keksdose's words\n * (`auth.reset.*`), which kastlan took over. */\nexport interface ResetPasswordLabels {\n /** The heading, on every state. */\n title: string;\n /** While the link is checked. */\n checking: string;\n /** Over the fields, given the account's address (when the check returned one). */\n intro: (email: string) => string;\n newPassword: string;\n confirmPassword: string;\n /** Under the confirmation while it differs. */\n mismatch: string;\n submit: string;\n /** The new password was not saved, for a reason that is not the link. */\n failed: string;\n /** The page was opened without a `token`. */\n noToken: string;\n /** The link is unknown, spent or expired — one sentence, as the server gives one\n * code (`token_invalid`). */\n invalid: string;\n /** Under it. */\n invalidHint: string;\n /** The way forward from an invalid link: back to \"Forgot password\". */\n requestNew: string;\n /** Done. */\n success: string;\n /** Under it: a reset ends every session (§6.3). */\n sessionsEnded: string;\n /** The button out — to sign-in, with the address filled in. */\n signIn: string;\n /** 0.30.0: the save was throttled — HTTP 429 ({@link isRateLimited}) — given the\n * `Retry-After` wait in seconds, or `undefined` without one. OPTIONAL, like every key\n * added to a shipped interface; the provider's `resetPassword`, then English, fill\n * it. */\n rateLimited?: (seconds?: number) => string;\n}\n\n/** `Required`: every key, the 0.30 one included, has its English here. */\nexport const DEFAULT_RESET_PASSWORD_LABELS: Required<ResetPasswordLabels> = {\n title: \"Choose a new password\",\n checking: \"Checking the link…\",\n intro: (email) => `You’re setting a new password for ${email}.`,\n newPassword: \"New password\",\n confirmPassword: \"Repeat new password\",\n mismatch: \"The passwords don’t match.\",\n submit: \"Save password\",\n failed: \"The password could not be changed.\",\n noToken: \"This link is incomplete.\",\n invalid: \"This link is invalid or has expired.\",\n invalidHint: \"Links are valid for one hour and work only once. Just request a new one.\",\n requestNew: \"Request a new link\",\n success: \"Your password has been changed. You can sign in with it now.\",\n sessionsEnded: \"Signed-in devices were signed out — you’ll need to sign in again there.\",\n signIn: \"Go to sign in\",\n rateLimited: englishRateLimited,\n};\n\n/* ── Types ───────────────────────────────────────────────────────────────── */\n\n/** What `onCheck` may resolve with — keksdose's `/password-reset/check` answer. */\nexport interface ResetPasswordCheck {\n /** The account's address: named over the fields (\"You're setting a new password for\n * …\") and handed to the password manager, which files the new password under it. */\n email?: string;\n /** The app's notices over the fields, shown BEFORE the password is typed — keksdose's\n * \"your account is end-to-end encrypted: this restores your sign-in, not your data\". */\n notices?: ReactNode;\n}\n\n/** What `onSubmit` hands over. */\nexport interface ResetPasswordValues {\n token: string;\n password: string;\n}\n\n/** What `onSubmit` resolves with — keksdose's `/password-reset/confirm` answer, which\n * carries no tokens (§6.3). */\nexport interface ResetPasswordResult {\n /** The account's address — the sign-in it leads to is filled in with it. */\n email: string;\n /** The app's outcomes, shown on the done state: keksdose's recovery-code notice for an\n * encrypted account, \"Your 2 personal access tokens were revoked\". */\n notices?: ReactNode;\n}\n\ntype Phase =\n | { kind: \"form\"; check: ResetPasswordCheck }\n | { kind: \"invalid\" }\n | { kind: \"done\"; result: ResetPasswordResult };\n\nexport interface ResetPasswordFormProps\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onSubmit\" | \"children\" | \"title\"> {\n /** The link's token — the app's `?token=` (keksdose, kastlan: `/reset-password?token=…`).\n * Empty: the link was cut short, and the page says so without asking anyone. */\n token: string;\n /**\n * Check the link before the form shows (`/auth/password-reset/check`) — once per\n * token, on mount. Checking does not use it up, so a reload is free. Resolve (with\n * the address and any notices) for a live link; reject for a dead one, and the page\n * says \"This link is invalid or has expired\" with the way to a new one.\n */\n onCheck: (token: string) => Promise<ResetPasswordCheck | void | undefined>;\n /**\n * The new password was submitted: send `/auth/password-reset/confirm`. Resolve with\n * the account's address (and the app's notices) — no tokens: a reset is not a sign-in\n * (§6.3). Reject with the client's error: `token_invalid` (the link expired or was\n * used in another tab while the form was open) goes to the invalid state; anything\n * else stays on the form with the password kept.\n */\n onSubmit: (values: ResetPasswordValues) => Promise<ResetPasswordResult>;\n /** \"Go to sign in\" calls this with the address, for an app that routes in code.\n * Without it, the button is a link to `signInHref`. */\n onSignIn?: (email: string) => void;\n /** Where \"Go to sign in\" leads, with `?email=` added — read it into `SignInForm`'s\n * `defaultEmail`. Default `/login`. */\n signInHref?: string;\n /** \"Request a new link\" — the app's \"Forgot password\" page. Default\n * `/forgot-password`. */\n forgotHref?: string;\n /** The app's words for a failed save (the device offline), or `undefined` for the\n * kit's: `rateLimited` for a bare `429` (0.30.0), else `failed`. Not asked for\n * `token_invalid`, which is a state. */\n describeError?: (error: unknown) => ReactNode | undefined;\n /** The heading. Default `labels.title`; `null` draws none, for a page that puts it\n * in `AuthLayout`'s `title` instead. */\n title?: ReactNode;\n /** The heading's level. Default `h2`, under the page's `h1`. */\n headingAs?: AuthHeadingLevel;\n labels?: Partial<ResetPasswordLabels>;\n}\n\n/**\n * Redeem a password-reset link (`/reset-password?token=…`, docs/auth-harmonization.md\n * §6.3, §7) — keksdose's `ResetPasswordPage` (features/auth/reset-password-page.tsx),\n * which kastlan built its own on.\n *\n * **The link is checked first** (`onCheck`), and only then does the form appear: an\n * expired link should say so before someone types a new password twice, not after.\n *\n * **A reset is not a sign-in** (§6.3, §10.11). The confirm answers without tokens, so a\n * 2FA account cannot skip its second factor by way of its inbox, and the page ends on\n * \"Go to sign in\" with the address filled in — the person has just typed the new\n * password twice; signing in is one step. What else the reset did is said there:\n * every other session ended (the kit's line, true in all three apps), and the app's own\n * outcomes in `notices` — keksdose's recovery-code notice and its revoked API tokens.\n *\n * **The password** is chosen with the same fields as `RegisterForm` and `SignInForm`'s\n * set-password step ({@link NewPasswordFields}): the strength meter and its checklist as\n * advice, and only the two hard rules — at least 8 characters, at most 72 bytes (§8).\n * The submit waits for both and a matching confirmation.\n *\n * The form never sends a request itself (§8): the token and the password go to the\n * callbacks, and the page renders what they resolve with.\n */\nexport function ResetPasswordForm({\n token,\n onCheck,\n onSubmit,\n onSignIn,\n signInHref = \"/login\",\n forgotHref = \"/forgot-password\",\n describeError,\n title,\n headingAs: Heading = \"h2\",\n labels: labelsProp,\n className,\n ...rest\n}: ResetPasswordFormProps) {\n const labels = useKitLabels(\"resetPassword\", DEFAULT_RESET_PASSWORD_LABELS, labelsProp);\n // The phase belongs to the token it was reached with: a new token starts over at the\n // check without a reset effect.\n const [phase, setPhase] = useState<{ token: string; phase: Phase } | null>(null);\n const current: Phase | \"checking\" =\n token === \"\" ? { kind: \"invalid\" } : phase?.token === token ? phase.phase : \"checking\";\n\n useOncePerKey(token === \"\" ? null : token, onCheck, (key, result) =>\n setPhase({\n token: key,\n phase: result.ok ? { kind: \"form\", check: result.value ?? {} } : { kind: \"invalid\" },\n }),\n );\n\n const [password, setPassword] = useState(\"\");\n const [confirm, setConfirm] = useState(\"\");\n const [pending, setPending] = useState(false);\n const [failure, setFailure] = useState<ReactNode>(null);\n const headingId = useId();\n const passwordRef = useRef<HTMLInputElement>(null);\n const doneRef = useRef<HTMLDivElement>(null);\n const kind = current === \"checking\" ? \"checking\" : current.kind;\n\n // The form arrives after the check: the field is where the person is going.\n useEffect(() => {\n if (kind === \"form\") passwordRef.current?.focus();\n }, [kind]);\n useFocusWhen(kind === \"done\", doneRef);\n\n const heading =\n title === null ? null : (\n <Heading id={headingId} className={FORM_HEADING_CLASS}>\n {title ?? labels.title}\n </Heading>\n );\n const rootClass = cn(\"space-y-3\", className);\n\n if (current === \"checking\") {\n return (\n <div {...rest} data-state=\"checking\" aria-busy className={rootClass}>\n {heading}\n <LoadingState size=\"sm\" label={labels.checking} />\n </div>\n );\n }\n\n if (current.kind === \"invalid\") {\n return (\n <div {...rest} data-state=\"invalid\" className={rootClass}>\n {heading}\n <EmptyState\n tone=\"danger\"\n icon={<XCircle />}\n title={token === \"\" ? labels.noToken : labels.invalid}\n hint={labels.invalidHint}\n action={\n <Button href={forgotHref} variant=\"brand\">\n {labels.requestNew}\n </Button>\n }\n className={OUTCOME_CLASS}\n />\n </div>\n );\n }\n\n if (current.kind === \"done\") {\n const { email, notices } = current.result;\n return (\n <div {...rest} data-state=\"done\" className={rootClass}>\n {heading}\n <OutcomeMessage icon={<CheckCircle2 className=\"text-[var(--success)]\" />} focusRef={doneRef}>\n <p className={INTRO_CLASS}>{labels.success}</p>\n </OutcomeMessage>\n {notices}\n <p className=\"text-xs text-[var(--text-muted)]\">{labels.sessionsEnded}</p>\n {onSignIn ? (\n <Button type=\"button\" variant=\"brand\" className=\"w-full\" onClick={() => onSignIn(email)}>\n {labels.signIn}\n </Button>\n ) : (\n <Button href={email ? withQuery(signInHref, \"email\", email) : signInHref} variant=\"brand\" className=\"w-full\">\n {labels.signIn}\n </Button>\n )}\n </div>\n );\n }\n\n const { email, notices } = current.check;\n const problem = newPasswordProblem(password, confirm);\n\n const submit = (e: FormEvent) => {\n e.preventDefault();\n if (pending || problem !== null) return;\n setFailure(null);\n setPending(true);\n Promise.resolve()\n .then(() => onSubmit({ token, password }))\n .then(\n (result) => {\n setPending(false);\n setPassword(\"\");\n setConfirm(\"\");\n setPhase({ token, phase: { kind: \"done\", result } });\n },\n (error: unknown) => {\n setPending(false);\n if (authErrorCode(error) === \"token_invalid\") {\n setPassword(\"\");\n setConfirm(\"\");\n setPhase({ token, phase: { kind: \"invalid\" } });\n return;\n }\n // The app's words first, then the throttle's, then the kit's catch-all.\n setFailure(\n describeError?.(error) ??\n (isRateLimited(error)\n ? (labels.rateLimited ?? DEFAULT_RESET_PASSWORD_LABELS.rateLimited)(retryAfterSeconds(error))\n : labels.failed),\n );\n },\n );\n };\n\n return (\n <div {...rest} data-state=\"form\" className={rootClass}>\n <form className=\"space-y-3\" aria-labelledby={title === null ? undefined : headingId} onSubmit={submit}>\n {heading}\n {email ? <p className={INTRO_CLASS}>{labels.intro(email)}</p> : null}\n {notices}\n {/* Which account the new password is for, for the password manager: it files\n the new password under this username instead of guessing (kastlan). */}\n {email ? <input type=\"email\" name=\"username\" autoComplete=\"username\" value={email} readOnly hidden /> : null}\n <NewPasswordFields\n password={password}\n confirm={confirm}\n onPasswordChange={(next) => {\n setPassword(next);\n if (failure) setFailure(null);\n }}\n onConfirmChange={setConfirm}\n busy={pending}\n passwordRef={passwordRef}\n text={{ password: labels.newPassword, confirm: labels.confirmPassword, mismatch: labels.mismatch }}\n />\n {failure != null && (\n <AlertBanner tone=\"danger\" size=\"sm\" role=\"alert\">\n {failure}\n </AlertBanner>\n )}\n <Button type=\"submit\" className=\"w-full\" disabled={!pending && problem !== null} pending={pending}>\n {labels.submit}\n </Button>\n </form>\n </div>\n );\n}\n"],"mappings":";AAgOM,cAQA,YARA;AAhON,SAAS,WAAW,OAAO,QAAQ,gBAAgB;AAEnD,SAAS,cAAc,eAAe;AACtC,SAAS,UAAU;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AAC,IAC1F,OAAO;AAAA,QACf;AAAA,MACF;AAAA,IACF;AAAA,EACJ;AAEA,SACE,oBAAC,SAAK,GAAG,MAAM,cAAW,QAAO,WAAW,WAC1C,+BAAC,UAAK,WAAU,aAAY,mBAAiB,UAAU,OAAO,SAAY,WAAW,UAAU,QAC5F;AAAA;AAAA,IACA,QAAQ,oBAAC,OAAE,WAAW,aAAc,iBAAO,MAAM,KAAK,GAAE,IAAO;AAAA,IAC/D;AAAA,IAGA,QAAQ,oBAAC,WAAM,MAAK,SAAQ,MAAK,YAAW,cAAa,YAAW,OAAO,OAAO,UAAQ,MAAC,QAAM,MAAC,IAAK;AAAA,IACxG;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,kBAAkB,CAAC,SAAS;AAC1B,sBAAY,IAAI;AAChB,cAAI,QAAS,YAAW,IAAI;AAAA,QAC9B;AAAA,QACA,iBAAiB;AAAA,QACjB,MAAM;AAAA,QACN;AAAA,QACA,MAAM,EAAE,UAAU,OAAO,aAAa,SAAS,OAAO,iBAAiB,UAAU,OAAO,SAAS;AAAA;AAAA,IACnG;AAAA,IACC,WAAW,QACV,oBAAC,eAAY,MAAK,UAAS,MAAK,MAAK,MAAK,SACvC,mBACH;AAAA,IAEF,oBAAC,UAAO,MAAK,UAAS,WAAU,UAAS,UAAU,CAAC,WAAW,YAAY,MAAM,SAC9E,iBAAO,QACV;AAAA,KACF,GACF;AAEJ;","names":["email","notices"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
3
|
+
import { AccessChoice } from '../landing/access.js';
|
|
4
|
+
import '../landing/landing-labels.js';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* What a sign-in call answers, in the kit's words — docs/auth-harmonization.md §5.1,
|
|
@@ -53,8 +55,17 @@ interface SignInCredentials {
|
|
|
53
55
|
}
|
|
54
56
|
interface SignInCodeValues {
|
|
55
57
|
challengeToken: string;
|
|
56
|
-
/** Digits only — {@link OneTimeCodeInput} drops the spaces of "123 456".
|
|
58
|
+
/** Digits only — {@link OneTimeCodeInput} drops the spaces of "123 456". A backup code
|
|
59
|
+
* (`kind: "recovery"`) is trimmed and otherwise as typed: its dashes and case are the
|
|
60
|
+
* server's to normalise, as kastlan's `_normalise_backup_code` does. */
|
|
57
61
|
code: string;
|
|
62
|
+
/**
|
|
63
|
+
* 0.30.0: `"recovery"` when the person typed one of their backup codes instead
|
|
64
|
+
* (`recoveryCode`); absent for the authenticator's code, as before. kastlan's
|
|
65
|
+
* `/auth/login/2fa` takes either in the same `code` and tells them apart itself; an
|
|
66
|
+
* app whose server takes a backup code elsewhere routes on this.
|
|
67
|
+
*/
|
|
68
|
+
kind?: "recovery";
|
|
58
69
|
}
|
|
59
70
|
interface SignInNewPasswordValues {
|
|
60
71
|
challengeToken: string;
|
|
@@ -117,8 +128,28 @@ interface SignInLabels {
|
|
|
117
128
|
expired: string;
|
|
118
129
|
/** From the second and third step back to the credentials. */
|
|
119
130
|
backToSignIn: string;
|
|
131
|
+
/** The second-factor step's switch to a backup code (`recoveryCode`). */
|
|
132
|
+
useRecoveryCode?: string;
|
|
133
|
+
/** The switch back, from the backup-code field to the authenticator's code. */
|
|
134
|
+
useAuthenticatorCode?: string;
|
|
135
|
+
/** The backup-code field's label. */
|
|
136
|
+
recoveryCode?: string;
|
|
137
|
+
/** The step's intro while a backup code is asked for, in place of `twoFactorIntro`. */
|
|
138
|
+
recoveryIntro?: string;
|
|
139
|
+
/** Under the backup-code field, given how many letters and digits a code has. */
|
|
140
|
+
recoveryCodeHint?: (length: number) => string;
|
|
141
|
+
/** A refused backup code — wrong, or spent already (each one works once). */
|
|
142
|
+
recoveryCodeInvalid?: string;
|
|
143
|
+
/** Any step's request was throttled — HTTP 429 ({@link isRateLimited}) — given the
|
|
144
|
+
* wait its `Retry-After` asks for, in seconds ({@link retryAfterSeconds}), or
|
|
145
|
+
* `undefined` (or `0`) without one. */
|
|
146
|
+
rateLimited?: (seconds?: number) => string;
|
|
147
|
+
/** 0.31.0: the link after `noAccount` for an invitation-only app (`access` of kind
|
|
148
|
+
* `request`) — a mail to support, in place of `register`. */
|
|
149
|
+
requestAccess?: string;
|
|
120
150
|
}
|
|
121
|
-
|
|
151
|
+
/** `Required`: every key, the 0.30 ones included, has its English here. */
|
|
152
|
+
declare const DEFAULT_SIGN_IN_LABELS: Required<SignInLabels>;
|
|
122
153
|
interface SignInFormProps extends Omit<ComponentPropsWithoutRef<"div">, "onSubmit" | "children"> {
|
|
123
154
|
/**
|
|
124
155
|
* The credentials step was submitted. Send them, and resolve with the answer
|
|
@@ -159,6 +190,15 @@ interface SignInFormProps extends Omit<ComponentPropsWithoutRef<"div">, "onSubmi
|
|
|
159
190
|
forgotHref?: string;
|
|
160
191
|
/** "No account yet? Create account" goes here — `/register`. Left out, no line. */
|
|
161
192
|
registerHref?: string;
|
|
193
|
+
/**
|
|
194
|
+
* 0.31.0 (docs/landing-demo-harmonization.md §4.2): how a visitor gets an account —
|
|
195
|
+
* the same value the landing's `PublicHeader` and `Hero` take. `{kind: "request",
|
|
196
|
+
* email}` turns the line into "No account yet? Request access", a mail to support with
|
|
197
|
+
* the subject and body of `accessAction` (every app is invitation-only); `{kind:
|
|
198
|
+
* "register", href}` keeps "Create account", to `href`. Wins over `registerHref`; left
|
|
199
|
+
* out, `registerHref` works as before.
|
|
200
|
+
*/
|
|
201
|
+
access?: AccessChoice;
|
|
162
202
|
/** The email field's start value — the reset page ends on "Sign in" with the address
|
|
163
203
|
* filled in (§6.3). */
|
|
164
204
|
defaultEmail?: string;
|
|
@@ -176,10 +216,28 @@ interface SignInFormProps extends Omit<ComponentPropsWithoutRef<"div">, "onSubmi
|
|
|
176
216
|
deactivatedContact?: ReactNode;
|
|
177
217
|
/** Digits of the second factor. Default 6 (TOTP). */
|
|
178
218
|
codeLength?: number;
|
|
219
|
+
/**
|
|
220
|
+
* 0.30.0: offer a backup code on the second-factor step (kastlan's 0.29 adoption: its
|
|
221
|
+
* `/auth/login/2fa` takes one of the eight codes minted at 2FA setup, and the kit's
|
|
222
|
+
* step had no way to type one). A "Use a backup code" switch under the code field
|
|
223
|
+
* swaps the digits-only {@link OneTimeCodeInput} for a plain text field; the code goes
|
|
224
|
+
* to `onCode` with the same challenge and `kind: "recovery"`.
|
|
225
|
+
*
|
|
226
|
+
* `true` for a 16-character code (kastlan's `ABCD-EFGH-JKLM-NPQR`), or `{ length }`.
|
|
227
|
+
* The length counts letters and digits only — the dashes and spaces a printed code is
|
|
228
|
+
* grouped with don't count — and "Verify" waits for it. Left out, no switch.
|
|
229
|
+
*/
|
|
230
|
+
recoveryCode?: boolean | {
|
|
231
|
+
length?: number;
|
|
232
|
+
};
|
|
179
233
|
/** App content at the top of the credentials step — a notice, a demo button. */
|
|
180
234
|
credentialsContent?: ReactNode;
|
|
181
|
-
/**
|
|
182
|
-
|
|
235
|
+
/**
|
|
236
|
+
* App content on the second-factor step, under its intro. 0.30.0: pass a function and
|
|
237
|
+
* it gets the challenge token — kastlan kept its own copy of the token for a "lost
|
|
238
|
+
* your device?" link, which the step now hands over.
|
|
239
|
+
*/
|
|
240
|
+
twoFactorContent?: ReactNode | ((challengeToken: string) => ReactNode);
|
|
183
241
|
/**
|
|
184
242
|
* App content on the set-a-new-password step, under its intro — keksdose's
|
|
185
243
|
* private-mode note ("Your encrypted data is untouched …"), which depends on the
|
|
@@ -187,9 +245,10 @@ interface SignInFormProps extends Omit<ComponentPropsWithoutRef<"div">, "onSubmi
|
|
|
187
245
|
*/
|
|
188
246
|
passwordChangeContent?: ReactNode | ((extra: Readonly<Record<string, unknown>> | undefined) => ReactNode);
|
|
189
247
|
/**
|
|
190
|
-
* The app's own words for a failure, or `undefined` for the kit's:
|
|
191
|
-
*
|
|
192
|
-
* returns replaces the message, and the `invalid_credentials` hints
|
|
248
|
+
* The app's own words for a failure, or `undefined` for the kit's: the device being
|
|
249
|
+
* offline, a throttle with its wait ("try again in an hour"). Asked first, for every
|
|
250
|
+
* failure; what it returns replaces the message, and the `invalid_credentials` hints
|
|
251
|
+
* still follow. A bare `429` needs none since 0.30.0: the kit says `rateLimited`.
|
|
193
252
|
*/
|
|
194
253
|
describeError?: (error: unknown, action: SignInAction) => ReactNode | undefined;
|
|
195
254
|
/** The step changed — retitle the page (`AuthLayout`'s `title`) if the app wants. */
|
|
@@ -230,7 +289,14 @@ interface SignInFormProps extends Omit<ComponentPropsWithoutRef<"div">, "onSubmi
|
|
|
230
289
|
* whole code. A refused code stays here with its error; `token_invalid` (the
|
|
231
290
|
* challenge expired) goes back to the credentials and says why. Kurvenschmiede has
|
|
232
291
|
* no 2FA yet, and the step is here from the start, so adding it is backend work only
|
|
233
|
-
* (§10.5).
|
|
292
|
+
* (§10.5). With `recoveryCode` (0.30.0) a switch under the field takes a backup code
|
|
293
|
+
* instead, through the same `onCode` with `kind: "recovery"`.
|
|
294
|
+
*
|
|
295
|
+
* **A throttled request** (HTTP 429, {@link isRateLimited}) says "Too many attempts. Try
|
|
296
|
+
* again in 30 s." on any step (0.30.0) — the wait from its `Retry-After`, else "Wait a
|
|
297
|
+
* moment and try again." — after `describeError`, whose words still come first, and
|
|
298
|
+
* instead of "wrong password" or "invalid code", which would send the person to try
|
|
299
|
+
* another one.
|
|
234
300
|
* - New password: new + confirm with the strength meter, the 8-character / 72-byte
|
|
235
301
|
* rules and nothing else (§8). It reads as explained, not blocked (keksdose): the
|
|
236
302
|
* person did nothing wrong.
|
|
@@ -238,6 +304,6 @@ interface SignInFormProps extends Omit<ComponentPropsWithoutRef<"div">, "onSubmi
|
|
|
238
304
|
* The password is dropped from state once the credentials are answered; "Back to sign in"
|
|
239
305
|
* returns to an empty password field.
|
|
240
306
|
*/
|
|
241
|
-
declare function SignInForm({ onSubmit, onCode, onSetPassword, onPasskey, passkeyAutofill, forgotHref, registerHref, defaultEmail, emailTag, deactivatedContact, codeLength, credentialsContent, twoFactorContent, passwordChangeContent, describeError, onStepChange, headingAs: Heading, labels: labelsProp, className, ...rest }: SignInFormProps): react.JSX.Element;
|
|
307
|
+
declare function SignInForm({ onSubmit, onCode, onSetPassword, onPasskey, passkeyAutofill, forgotHref, registerHref, access, defaultEmail, emailTag, deactivatedContact, codeLength, recoveryCode, credentialsContent, twoFactorContent, passwordChangeContent, describeError, onStepChange, headingAs: Heading, labels: labelsProp, className, ...rest }: SignInFormProps): react.JSX.Element;
|
|
242
308
|
|
|
243
309
|
export { DEFAULT_SIGN_IN_LABELS, type SignInAction, type SignInAnswer, type SignInCodeValues, type SignInCredentials, SignInForm, type SignInFormProps, type SignInLabels, type SignInNewPasswordValues, type SignInStep };
|