@softure-ai/auth 0.2.2 → 0.2.4
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/CHANGELOG.md +32 -0
- package/README.md +33 -3
- package/dist/index.js +1 -1
- package/dist/scripts/create-account.d.ts +18 -0
- package/dist/scripts/create-account.d.ts.map +1 -0
- package/dist/scripts/create-account.js +56 -0
- package/dist/scripts/create-account.js.map +1 -0
- package/dist/scripts/index.d.ts +1 -0
- package/dist/scripts/index.d.ts.map +1 -1
- package/dist/scripts/index.js +4 -3
- package/dist/scripts/index.js.map +1 -1
- package/dist/scripts/password-choice.d.ts +22 -0
- package/dist/scripts/password-choice.d.ts.map +1 -0
- package/dist/scripts/password-choice.js +23 -0
- package/dist/scripts/password-choice.js.map +1 -0
- package/dist/scripts/temporary-password.d.ts.map +1 -1
- package/dist/scripts/temporary-password.js +4 -19
- package/dist/scripts/temporary-password.js.map +1 -1
- package/dist/ui/auth-forms.d.ts +19 -6
- package/dist/ui/auth-forms.d.ts.map +1 -1
- package/dist/ui/auth-forms.js +64 -20
- package/dist/ui/auth-forms.js.map +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js.map +1 -1
- package/module.json +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/scripts/create-account.ts +71 -0
- package/src/scripts/index.ts +4 -3
- package/src/scripts/password-choice.ts +33 -0
- package/src/scripts/temporary-password.ts +4 -22
- package/src/ui/auth-forms.tsx +129 -45
- package/src/ui/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,38 @@ Newest first. Each version lists what changed for an app that uses `@softure-ai/
|
|
|
4
4
|
production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
|
|
5
5
|
"Definition of done"). Versions before the first one below are described in their GitHub Releases (`auth@x.y.z`).
|
|
6
6
|
|
|
7
|
+
## 0.2.4
|
|
8
|
+
|
|
9
|
+
All additive (#588); existing calls keep their fields, names and look.
|
|
10
|
+
|
|
11
|
+
- `RegisterForm`'s consent box shows `errors.auth.consent_required` under the box when a submit finds it unticked,
|
|
12
|
+
instead of the browser's own bubble, and takes focus when it is the first invalid control; ticking it clears the
|
|
13
|
+
message. It takes `consentProps` (`{ id, classNames }`, `ConsentProps`), so with `id: "field-consent"` the box is
|
|
14
|
+
`#field-consent` and its error `#field-consent-error`.
|
|
15
|
+
- A server error for a field a form does not render (e.g. `consent` with `requireConsent={false}`) now shows as the
|
|
16
|
+
form error instead of being dropped.
|
|
17
|
+
- Every form takes `fieldClassNames` (ui's `InputFieldSlot`s: `label`, `hint`, `input`, ...), `fieldHintAs` and
|
|
18
|
+
`fieldHintProps`, passed to each of its text and password fields.
|
|
19
|
+
|
|
20
|
+
Migration for an app that turned the box off and rendered its own (`requireConsent={false}` plus a `CheckboxField`
|
|
21
|
+
in `extraFields`):
|
|
22
|
+
|
|
23
|
+
1. Drop `requireConsent={false}` and the app's consent box from `extraFields`; pass the statement as `consentLabel`.
|
|
24
|
+
2. Pass `consentProps={{ id: "field-consent" }}` (the id the app's tests use) and the box's classes in
|
|
25
|
+
`consentProps.classNames`.
|
|
26
|
+
3. Pass the app's field look as `fieldClassNames` (e.g. `{ label: "…" }`) and, for "?" hints, `fieldHintAs="tooltip"`
|
|
27
|
+
with `fieldHintProps`.
|
|
28
|
+
4. An app with its own translation already has `errors.auth.consent_required`; its wording is the box's message.
|
|
29
|
+
|
|
30
|
+
## 0.2.3
|
|
31
|
+
|
|
32
|
+
- `createCreateAccountScript(config, { maxAccounts?, alphabet?, clock? })` in `@softure-ai/auth/scripts` (#521): the
|
|
33
|
+
`create-account` ops script creates an account while registration is closed, with a drawn temporary password or a
|
|
34
|
+
given `--password-hash`, dry run by default. It refuses an existing or invalid email and, with `maxAccounts`, a
|
|
35
|
+
table that already holds that many accounts (the table is locked for the run). Migrate (optional): an app that
|
|
36
|
+
inserted its first account into `auth.users` itself, or added its own index to hold one account, uses the script
|
|
37
|
+
with `maxAccounts: 1` instead.
|
|
38
|
+
|
|
7
39
|
## 0.2.2
|
|
8
40
|
|
|
9
41
|
- Password reset mails can leave from a background job with retry (#494): `auth({ passwordReset: { send, enqueue:
|
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Users and sessions in the `auth` schema, scrypt password hashes, opaque session
|
|
|
12
12
|
login, logout, password change and password reset as server actions and pages, `getCurrentUser` / `requireUser`
|
|
13
13
|
for server code, roles (`requireRole`, `authorizeRole`, `hasRole`, and `grant-role` /
|
|
14
14
|
`revoke-role` scripts), account recovery (`revokeUserSessions` and a `set-temporary-password`
|
|
15
|
-
script), `createAuthGuard` for the app's `proxy.ts`, and a health check that
|
|
15
|
+
script), a `create-account` script for the first account of an app with registration closed, `createAuthGuard` for the app's `proxy.ts`, and a health check that
|
|
16
16
|
`GET /api/health` of `@softure-ai/ops` runs (every auth table answers, no rows read).
|
|
17
17
|
`@softure-ai/auth/mailing` sends password reset mails through `@softure-ai/mailing`
|
|
18
18
|
(`mailingResetSender()`); `@softure-ai/auth/jobs` sends them from a background job of `@softure-ai/jobs` with
|
|
@@ -366,6 +366,28 @@ the first login. `isPasswordHash(value)` checks the format locally, exactly: a h
|
|
|
366
366
|
a character outside base64url or a cost scrypt refuses is not a hash `hashPassword` writes, so the script refuses it
|
|
367
367
|
instead of storing a hash no password matches.
|
|
368
368
|
|
|
369
|
+
**First account.** An app with registration closed (`registrationClosed: true`, no `/register` page) creates its
|
|
370
|
+
owner's account with the `create-account` ops script. It draws a temporary password exactly like
|
|
371
|
+
`set-temporary-password` (or stores a `--password-hash` made locally, the same way), refuses an invalid email and an
|
|
372
|
+
email that already has an account, and works whether registration is open or not:
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
// scripts/create-account.ts (bundled and run like grant-role)
|
|
376
|
+
import { createCreateAccountScript } from "@softure-ai/auth/scripts";
|
|
377
|
+
import { runOpsScript } from "@softure-ai/ops/scripts";
|
|
378
|
+
import config from "../softure.config";
|
|
379
|
+
|
|
380
|
+
process.exitCode = await runOpsScript({ script: createCreateAccountScript(config, { maxAccounts: 1 }), argv: process.argv.slice(2), config });
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
`node create-account.mjs --email=owner@example.com` shows the account it would create and rolls back; `--commit`
|
|
384
|
+
writes and prints the password once (or `passwordFrom: "hash"`). The report names the user id and the number of
|
|
385
|
+
accounts, never the email. `maxAccounts` (a whole number of at least 1, no limit by default) makes the script refuse
|
|
386
|
+
once `auth.users` holds that many accounts, whoever created them; the script locks the table for its run, so two runs
|
|
387
|
+
cannot both pass the limit. The app's `onRegistered` hook does not run (no consent, no registration fields): an app
|
|
388
|
+
that keeps its own rows per account creates them in its own script. `alphabet` and `clock` work as for
|
|
389
|
+
`createSetTemporaryPasswordScript`.
|
|
390
|
+
|
|
369
391
|
**Development seed.** `runSeedAccount` from `@softure-ai/auth/scripts` creates a login account for local
|
|
370
392
|
development from `SEED_EMAIL` and `SEED_PASSWORD` through `registerUser`, so the app's `onRegistered` hook runs as
|
|
371
393
|
for a real sign-up, and ends the session registration opens:
|
|
@@ -481,7 +503,10 @@ await runJobWorkerProcess({ config, handlers: { ...passwordResetJobHandlers, ...
|
|
|
481
503
|
**Your own forms.** `@softure-ai/auth/ui` exports `LoginForm`, `RegisterForm`,
|
|
482
504
|
`ChangePasswordForm`, `ForgotPasswordForm` and `ResetPasswordForm`; pass them the actions from
|
|
483
505
|
`@softure-ai/auth/next`. `RegisterForm` takes `consentLabel` and `extraFields` like
|
|
484
|
-
`createRegisterPage
|
|
506
|
+
`createRegisterPage`, and `consentProps` (`{ id, classNames }`) for the consent box: an unticked box shows
|
|
507
|
+
`errors.auth.consent_required` under it instead of the browser's bubble, and the server's consent error shows there
|
|
508
|
+
too. A field error for a field the form does not render (e.g. `consent` with `requireConsent={false}`) shows as the
|
|
509
|
+
form error.
|
|
485
510
|
|
|
486
511
|
**Tests.** `createTestAccount(db, { email, password, roles?, scrypt? })` from `@softure-ai/auth/testing`
|
|
487
512
|
writes an account and its role rows in one transaction, hashed as registration hashes it, and returns
|
|
@@ -606,7 +631,10 @@ Pages and forms are built from `@softure-ai/ui` (Card, fields, Checkbox, Button)
|
|
|
606
631
|
compiled classes, so `@softure-ai/ui/styles.css` styles them and the `--sft-*` tokens theme them.
|
|
607
632
|
Each form takes `classNames` for its slots (`root`, `form`, `footer`, `link`, `notice`, and `submit`
|
|
608
633
|
for the submit button's class), `submitVariant` (a `Button` variant, `primary` by default) and
|
|
609
|
-
`unstyled
|
|
634
|
+
`unstyled`. `fieldClassNames` (the ui field slots: `label`, `hint`, `input`, ...), `fieldHintAs` and
|
|
635
|
+
`fieldHintProps` go to every text and password field of the form, so its labels and hints match the app's other
|
|
636
|
+
forms; `RegisterForm`'s consent box takes its look from `consentProps.classNames`. Pages are server components you can
|
|
637
|
+
replace with your own page around the forms.
|
|
610
638
|
|
|
611
639
|
## 9. Copy
|
|
612
640
|
|
|
@@ -666,5 +694,7 @@ Rate limit rows of `security` hold only SHA-256 prefixes of the email and user i
|
|
|
666
694
|
- A `next` path longer than 8192 characters is replaced by the default target, with a warning in
|
|
667
695
|
the log that names its length.
|
|
668
696
|
- A temporary password from the script is not forced to change at the next login.
|
|
697
|
+
- `maxAccounts` limits the `create-account` script only; registration does not count accounts. An app that must hold
|
|
698
|
+
at most N accounts keeps registration closed.
|
|
669
699
|
- A registration attempt reveals whether an email has an account (`auth.email_taken`); the
|
|
670
700
|
`register` rate limit bounds how fast anyone can ask.
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ export const AUTH_RATE_LIMIT_BUCKETS = {
|
|
|
36
36
|
export const auth = defineModule({
|
|
37
37
|
manifest: {
|
|
38
38
|
id: MODULE_ID,
|
|
39
|
-
version: "0.2.
|
|
39
|
+
version: "0.2.4",
|
|
40
40
|
dependsOn: { security: "^0.2.0", mailing: "^0.2.0?", ops: "^0.2.0?", jobs: "^0.1.1?" },
|
|
41
41
|
dbSchema: "auth",
|
|
42
42
|
tables: ["users", "sessions", "user_roles", "password_resets"],
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Clock, type SoftureConfig } from "@softure-ai/core";
|
|
2
|
+
import { type OpsScript } from "@softure-ai/ops/scripts";
|
|
3
|
+
export interface CreateAccountScriptArgs {
|
|
4
|
+
readonly email: string;
|
|
5
|
+
/** A hash from `hashPassword`, computed where the password was made; the script then draws none. */
|
|
6
|
+
readonly "password-hash"?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CreateAccountScriptOptions {
|
|
9
|
+
/** The time stored as `created_at` and `password_changed_at`; the system clock by default. */
|
|
10
|
+
readonly clock?: Clock;
|
|
11
|
+
/** The characters a drawn password uses (e.g. `READABLE_PASSWORD_ALPHABET`); base64url by default. */
|
|
12
|
+
readonly alphabet?: string;
|
|
13
|
+
/** The most accounts the app holds (e.g. 1 for a single-owner app); the script refuses beyond it. No limit by default. */
|
|
14
|
+
readonly maxAccounts?: number;
|
|
15
|
+
}
|
|
16
|
+
/** `create-account --email=… [--password-hash=…]`: a new account, with or without registration open. */
|
|
17
|
+
export declare function createCreateAccountScript(config: SoftureConfig, options?: CreateAccountScriptOptions): OpsScript<CreateAccountScriptArgs>;
|
|
18
|
+
//# sourceMappingURL=create-account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-account.d.ts","sourceRoot":"","sources":["../../src/scripts/create-account.ts"],"names":[],"mappings":"AAOA,OAAO,EAAmB,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAO3F,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,oGAAoG;IACpG,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,0BAA0B;IACzC,8FAA8F;IAC9F,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,sGAAsG;IACtG,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,0HAA0H;IAC1H,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAOD,wGAAwG;AACxG,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,0BAA+B,GAAG,SAAS,CAAC,uBAAuB,CAAC,CAkC7I"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// The first account of an app whose registration is closed: a safe ops script
|
|
2
|
+
// (`@softure-ai/ops/scripts`), dry run by default, `--commit` writes. It creates the account with a
|
|
3
|
+
// drawn temporary password, printed once, or with a `hashPassword` hash computed elsewhere
|
|
4
|
+
// (`--password-hash`, best through `--password-hash-file=-`). With `maxAccounts` it refuses once the
|
|
5
|
+
// table holds that many accounts; the table is locked for the run, so two runs cannot both pass.
|
|
6
|
+
// The app's `onRegistered` hook does not run: nobody gave consent and there are no registration
|
|
7
|
+
// fields. Reports carry the user id, never the email or the hash.
|
|
8
|
+
import { ok, systemClock } from "@softure-ai/core";
|
|
9
|
+
import { defineOpsScript, refuseOpsScript } from "@softure-ai/ops/scripts";
|
|
10
|
+
import { count, sql } from "drizzle-orm";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { users } from "../schema.js";
|
|
13
|
+
import { parseEmail } from "../server/validation.js";
|
|
14
|
+
import { choosePassword, describeChosenPassword, PASSWORD_HASH_KEY, PASSWORD_HASH_USAGE, passwordHashArg } from "./password-choice.js";
|
|
15
|
+
const scriptArgs = z.strictObject({
|
|
16
|
+
email: z.string().min(1, "--email=<account email> is required"),
|
|
17
|
+
[PASSWORD_HASH_KEY]: passwordHashArg,
|
|
18
|
+
});
|
|
19
|
+
/** `create-account --email=… [--password-hash=…]`: a new account, with or without registration open. */
|
|
20
|
+
export function createCreateAccountScript(config, options = {}) {
|
|
21
|
+
const { maxAccounts } = options;
|
|
22
|
+
if (maxAccounts !== undefined && !(Number.isInteger(maxAccounts) && maxAccounts >= 1)) {
|
|
23
|
+
throw new Error("@softure-ai/auth: createCreateAccountScript needs maxAccounts to be a whole number of at least 1");
|
|
24
|
+
}
|
|
25
|
+
const clock = options.clock ?? systemClock;
|
|
26
|
+
return defineOpsScript({
|
|
27
|
+
name: "create-account",
|
|
28
|
+
description: "Creates an account with the given email and a random password (or the given hash), also while registration is closed.",
|
|
29
|
+
usage: ["--email=<account email>", PASSWORD_HASH_USAGE],
|
|
30
|
+
args: scriptArgs,
|
|
31
|
+
secrets: [PASSWORD_HASH_KEY],
|
|
32
|
+
run: async (tx, args) => {
|
|
33
|
+
const email = parseEmail(args.email);
|
|
34
|
+
if (!email.ok)
|
|
35
|
+
return refuseOpsScript("the email is not valid");
|
|
36
|
+
// Conflicts with itself and with every insert, until the script's transaction ends.
|
|
37
|
+
await tx.execute(sql `LOCK TABLE auth.users IN SHARE ROW EXCLUSIVE MODE`);
|
|
38
|
+
const [counted] = await tx.select({ accounts: count() }).from(users);
|
|
39
|
+
const accounts = counted?.accounts ?? 0;
|
|
40
|
+
if (maxAccounts !== undefined && accounts >= maxAccounts) {
|
|
41
|
+
return refuseOpsScript(`the app already holds ${String(accounts)} account(s), its maxAccounts`);
|
|
42
|
+
}
|
|
43
|
+
const password = await choosePassword(args[PASSWORD_HASH_KEY], config, options.alphabet);
|
|
44
|
+
const now = clock.now();
|
|
45
|
+
const [created] = await tx
|
|
46
|
+
.insert(users)
|
|
47
|
+
.values({ email: email.value, passwordHash: password.hash, createdAt: now, passwordChangedAt: now })
|
|
48
|
+
.onConflictDoNothing({ target: users.email })
|
|
49
|
+
.returning({ id: users.id });
|
|
50
|
+
if (created === undefined)
|
|
51
|
+
return refuseOpsScript("an account with this email already exists");
|
|
52
|
+
return ok({ before: { accounts }, after: { userId: created.id, accounts: accounts + 1, ...describeChosenPassword(password) } });
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=create-account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-account.js","sourceRoot":"","sources":["../../src/scripts/create-account.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,oGAAoG;AACpG,2FAA2F;AAC3F,qGAAqG;AACrG,iGAAiG;AACjG,gGAAgG;AAChG,kEAAkE;AAClE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAkC,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAkB,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAiBvI,MAAM,UAAU,GAAG,CAAC,CAAC,YAAY,CAAC;IAChC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,qCAAqC,CAAC;IAC/D,CAAC,iBAAiB,CAAC,EAAE,eAAe;CACrC,CAAC,CAAC;AAEH,wGAAwG;AACxG,MAAM,UAAU,yBAAyB,CAAC,MAAqB,EAAE,UAAsC,EAAE;IACvG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,IAAI,WAAW,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,WAAW,IAAI,CAAC,CAAC,EAAE,CAAC;QACtF,MAAM,IAAI,KAAK,CAAC,kGAAkG,CAAC,CAAC;IACtH,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,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GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,CAAC;iBACnG,mBAAmB,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;iBAC5C,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC/B,IAAI,OAAO,KAAK,SAAS;gBAAE,OAAO,eAAe,CAAC,2CAA2C,CAAC,CAAC;YAC/F,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,GAAG,CAAC,EAAE,GAAG,sBAAsB,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;QAClI,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/scripts/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createGrantRoleScript, createRevokeRoleScript, type RoleScriptArgs, type RoleScriptOptions } from "./role-scripts.js";
|
|
2
2
|
export { createSetTemporaryPasswordScript, type TemporaryPasswordScriptArgs, type TemporaryPasswordScriptOptions, } from "./temporary-password.js";
|
|
3
|
+
export { createCreateAccountScript, type CreateAccountScriptArgs, type CreateAccountScriptOptions } from "./create-account.js";
|
|
3
4
|
export { runSeedAccount, type RunSeedAccountOptions } from "./seed-account.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC/H,OAAO,EACL,gCAAgC,EAChC,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,GACpC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC/H,OAAO,EACL,gCAAgC,EAChC,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,GACpC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,yBAAyB,EAAE,KAAK,uBAAuB,EAAE,KAAK,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAC/H,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/scripts/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// `@softure-ai/auth/scripts`: ops scripts that grant and revoke roles
|
|
2
|
-
// and the development seed account
|
|
3
|
-
// (see the README, "Roles", "Account recovery" and "Development seed").
|
|
1
|
+
// `@softure-ai/auth/scripts`: ops scripts that grant and revoke roles, set a temporary password and
|
|
2
|
+
// create an account, and the development seed account
|
|
3
|
+
// (see the README, "Roles", "Account recovery", "First account" and "Development seed").
|
|
4
4
|
export { createGrantRoleScript, createRevokeRoleScript } from "./role-scripts.js";
|
|
5
5
|
export { createSetTemporaryPasswordScript, } from "./temporary-password.js";
|
|
6
|
+
export { createCreateAccountScript } from "./create-account.js";
|
|
6
7
|
export { runSeedAccount } from "./seed-account.js";
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,sDAAsD;AACtD,yFAAyF;AACzF,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAA+C,MAAM,mBAAmB,CAAC;AAC/H,OAAO,EACL,gCAAgC,GAGjC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,yBAAyB,EAAiE,MAAM,qBAAqB,CAAC;AAC/H,OAAO,EAAE,cAAc,EAA8B,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SoftureConfig } from "@softure-ai/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export declare const PASSWORD_HASH_KEY = "password-hash";
|
|
4
|
+
export declare const PASSWORD_HASH_USAGE = "--password-hash=<hash> store this hashPassword() hash instead of drawing a password";
|
|
5
|
+
export declare const passwordHashArg: z.ZodOptional<z.ZodString>;
|
|
6
|
+
export type ChosenPassword = {
|
|
7
|
+
readonly from: "hash";
|
|
8
|
+
readonly hash: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly from: "drawn";
|
|
11
|
+
readonly hash: string;
|
|
12
|
+
readonly plain: string;
|
|
13
|
+
};
|
|
14
|
+
/** The given hash, or a drawn password of at least 20 characters and `password.minLength`, with its hash. */
|
|
15
|
+
export declare function choosePassword(givenHash: string | undefined, config: SoftureConfig, alphabet: string | undefined): Promise<ChosenPassword>;
|
|
16
|
+
/** What a report says about the stored password: never the hash, the drawn password once. */
|
|
17
|
+
export declare function describeChosenPassword(password: ChosenPassword): {
|
|
18
|
+
passwordFrom: "hash";
|
|
19
|
+
} | {
|
|
20
|
+
temporaryPassword: string;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=password-choice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-choice.d.ts","sourceRoot":"","sources":["../../src/scripts/password-choice.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AACjD,eAAO,MAAM,mBAAmB,yFAAgG,CAAC;AAGjI,eAAO,MAAM,eAAe,4BAAmG,CAAC;AAEhI,MAAM,MAAM,cAAc,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9E,6GAA6G;AAC7G,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,CAKhJ;AAED,6FAA6F;AAC7F,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAEzH"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { getAuthOptions } from "../server/options.js";
|
|
3
|
+
import { hashPassword, isPasswordHash } from "../server/password.js";
|
|
4
|
+
import { createTemporaryPassword } from "../server/temporary-password.js";
|
|
5
|
+
/** Long enough to be out of guessing range in any rate limit window. */
|
|
6
|
+
const MIN_TEMPORARY_LENGTH = 20;
|
|
7
|
+
export const PASSWORD_HASH_KEY = "password-hash";
|
|
8
|
+
export const PASSWORD_HASH_USAGE = `--${PASSWORD_HASH_KEY}=<hash> store this hashPassword() hash instead of drawing a password`;
|
|
9
|
+
// A constant message: the value is secret-derived and must not be echoed.
|
|
10
|
+
export const passwordHashArg = z.string().refine(isPasswordHash, "is not a scrypt hash written by @softure-ai/auth").optional();
|
|
11
|
+
/** The given hash, or a drawn password of at least 20 characters and `password.minLength`, with its hash. */
|
|
12
|
+
export async function choosePassword(givenHash, config, alphabet) {
|
|
13
|
+
if (givenHash !== undefined)
|
|
14
|
+
return { from: "hash", hash: givenHash };
|
|
15
|
+
const { password } = getAuthOptions(config);
|
|
16
|
+
const plain = createTemporaryPassword({ alphabet, length: Math.max(password.minLength, MIN_TEMPORARY_LENGTH) });
|
|
17
|
+
return { from: "drawn", hash: await hashPassword(plain, password.scrypt), plain };
|
|
18
|
+
}
|
|
19
|
+
/** What a report says about the stored password: never the hash, the drawn password once. */
|
|
20
|
+
export function describeChosenPassword(password) {
|
|
21
|
+
return password.from === "hash" ? { passwordFrom: "hash" } : { temporaryPassword: password.plain };
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=password-choice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-choice.js","sourceRoot":"","sources":["../../src/scripts/password-choice.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,wEAAwE;AACxE,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,CAAC,MAAM,iBAAiB,GAAG,eAAe,CAAC;AACjD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,iBAAiB,uEAAuE,CAAC;AAEjI,0EAA0E;AAC1E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,cAAc,EAAE,kDAAkD,CAAC,CAAC,QAAQ,EAAE,CAAC;AAMhI,6GAA6G;AAC7G,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,SAA6B,EAAE,MAAqB,EAAE,QAA4B;IACrH,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IACtE,MAAM,EAAE,QAAQ,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,uBAAuB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,oBAAoB,CAAC,EAAE,CAAC,CAAC;IAChH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;AACpF,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,sBAAsB,CAAC,QAAwB;IAC7D,OAAO,QAAQ,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;AACrG,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporary-password.d.ts","sourceRoot":"","sources":["../../src/scripts/temporary-password.ts"],"names":[],"mappings":"AAOA,OAAO,EAAmB,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"temporary-password.d.ts","sourceRoot":"","sources":["../../src/scripts/temporary-password.ts"],"names":[],"mappings":"AAOA,OAAO,EAAmB,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAQ3F,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,oGAAoG;IACpG,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,8BAA8B;IAC7C,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,sGAAsG;IACtG,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAOD,kHAAkH;AAClH,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE,8BAAmC,GAC3C,SAAS,CAAC,2BAA2B,CAAC,CAuBxC"}
|
|
@@ -10,18 +10,12 @@ import { defineOpsScript, refuseOpsScript } from "@softure-ai/ops/scripts";
|
|
|
10
10
|
import { eq } from "drizzle-orm";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { passwordResets, sessions, users } from "../schema.js";
|
|
13
|
-
import { getAuthOptions } from "../server/options.js";
|
|
14
|
-
import { hashPassword, isPasswordHash } from "../server/password.js";
|
|
15
13
|
import { revokeUserSessions } from "../server/sessions.js";
|
|
16
|
-
import { createTemporaryPassword } from "../server/temporary-password.js";
|
|
17
14
|
import { normalizeEmail } from "../server/validation.js";
|
|
18
|
-
|
|
19
|
-
const MIN_TEMPORARY_LENGTH = 20;
|
|
20
|
-
const PASSWORD_HASH_KEY = "password-hash";
|
|
15
|
+
import { choosePassword, describeChosenPassword, PASSWORD_HASH_KEY, PASSWORD_HASH_USAGE, passwordHashArg } from "./password-choice.js";
|
|
21
16
|
const scriptArgs = z.strictObject({
|
|
22
17
|
email: z.string().min(1, "--email=<account email> is required"),
|
|
23
|
-
|
|
24
|
-
[PASSWORD_HASH_KEY]: z.string().refine(isPasswordHash, "is not a scrypt hash written by @softure-ai/auth").optional(),
|
|
18
|
+
[PASSWORD_HASH_KEY]: passwordHashArg,
|
|
25
19
|
});
|
|
26
20
|
/** `set-temporary-password --email=… [--password-hash=…]`: a new password, every session and reset link ended. */
|
|
27
21
|
export function createSetTemporaryPasswordScript(config, options = {}) {
|
|
@@ -29,7 +23,7 @@ export function createSetTemporaryPasswordScript(config, options = {}) {
|
|
|
29
23
|
return defineOpsScript({
|
|
30
24
|
name: "set-temporary-password",
|
|
31
25
|
description: "Sets a new password for the account with the given email (a random one, or the given hash) and ends its sessions and reset link.",
|
|
32
|
-
usage: ["--email=<account email>",
|
|
26
|
+
usage: ["--email=<account email>", PASSWORD_HASH_USAGE],
|
|
33
27
|
args: scriptArgs,
|
|
34
28
|
secrets: [PASSWORD_HASH_KEY],
|
|
35
29
|
run: async (tx, args) => {
|
|
@@ -43,17 +37,8 @@ export function createSetTemporaryPasswordScript(config, options = {}) {
|
|
|
43
37
|
await revokeUserSessions(ctx, account.id);
|
|
44
38
|
await tx.delete(passwordResets).where(eq(passwordResets.userId, account.id));
|
|
45
39
|
const remaining = (await tx.select().from(sessions).where(eq(sessions.userId, account.id))).length;
|
|
46
|
-
|
|
47
|
-
return ok({ before, after: { userId: account.id, sessions: remaining, ...after } });
|
|
40
|
+
return ok({ before, after: { userId: account.id, sessions: remaining, ...describeChosenPassword(password) } });
|
|
48
41
|
},
|
|
49
42
|
});
|
|
50
43
|
}
|
|
51
|
-
/** The given hash, or a drawn password of at least 20 characters and `password.minLength`, with its hash. */
|
|
52
|
-
async function choosePassword(givenHash, config, alphabet) {
|
|
53
|
-
if (givenHash !== undefined)
|
|
54
|
-
return { from: "hash", hash: givenHash };
|
|
55
|
-
const { password } = getAuthOptions(config);
|
|
56
|
-
const plain = createTemporaryPassword({ alphabet, length: Math.max(password.minLength, MIN_TEMPORARY_LENGTH) });
|
|
57
|
-
return { from: "drawn", hash: await hashPassword(plain, password.scrypt), plain };
|
|
58
|
-
}
|
|
59
44
|
//# sourceMappingURL=temporary-password.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporary-password.js","sourceRoot":"","sources":["../../src/scripts/temporary-password.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,gGAAgG;AAChG,oG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O,CAAC,QAAQ,CAAC,CAAC;YACzF,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,iBAAiB,EAAE,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;YAC5H,MAAM,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;YAC1C,MAAM,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;YAC7E,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YACnG,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,sBAAsB,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;QACjH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/ui/auth-forms.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Locale } from "@softure-ai/core";
|
|
2
|
-
import { type ButtonVariant, type ClassNames } from "@softure-ai/ui";
|
|
2
|
+
import { type ButtonVariant, type CheckboxSlot, type ClassNames, type HintAppearance, type HintPlacement, type InputFieldSlot } from "@softure-ai/ui";
|
|
3
3
|
import { type ReactNode } from "react";
|
|
4
4
|
import { type AuthFormState } from "../contract.js";
|
|
5
5
|
import { type AuthMessages } from "../messages/index.js";
|
|
@@ -14,6 +14,17 @@ interface AuthFormBaseProps {
|
|
|
14
14
|
readonly unstyled?: boolean;
|
|
15
15
|
/** The submit button's look; `primary` by default. Its class goes in `classNames.submit`. */
|
|
16
16
|
readonly submitVariant?: ButtonVariant;
|
|
17
|
+
/** Classes for every text and password field of the form (label, hint, input, ...), to match the app's other forms. */
|
|
18
|
+
readonly fieldClassNames?: ClassNames<InputFieldSlot>;
|
|
19
|
+
/** Where the fields show their hints: under the label (default) or behind a "?" tooltip. */
|
|
20
|
+
readonly fieldHintAs?: HintPlacement;
|
|
21
|
+
/** The tooltip hint's look for every field, so it matches the app's standalone hints. */
|
|
22
|
+
readonly fieldHintProps?: HintAppearance;
|
|
23
|
+
}
|
|
24
|
+
/** The consent box's own props: its id (e.g. for the app's tests) and its look. */
|
|
25
|
+
export interface ConsentProps {
|
|
26
|
+
readonly id?: string;
|
|
27
|
+
readonly classNames?: ClassNames<CheckboxSlot>;
|
|
17
28
|
}
|
|
18
29
|
export interface LoginFormProps extends AuthFormBaseProps {
|
|
19
30
|
/** Where to go after login; checked again on the server. */
|
|
@@ -25,7 +36,7 @@ export interface LoginFormProps extends AuthFormBaseProps {
|
|
|
25
36
|
/** A confirmation shown under the form, e.g. after a password reset. */
|
|
26
37
|
readonly notice?: string;
|
|
27
38
|
}
|
|
28
|
-
export declare function LoginForm(
|
|
39
|
+
export declare function LoginForm(props: LoginFormProps): import("react").JSX.Element;
|
|
29
40
|
export interface RegisterFormProps extends AuthFormBaseProps {
|
|
30
41
|
readonly next?: string;
|
|
31
42
|
readonly loginHref?: string;
|
|
@@ -35,30 +46,32 @@ export interface RegisterFormProps extends AuthFormBaseProps {
|
|
|
35
46
|
readonly minPasswordLength: number;
|
|
36
47
|
/** The consent statement; may contain links to the terms. Defaults to `messages.fields.consent`. */
|
|
37
48
|
readonly consentLabel?: ReactNode;
|
|
49
|
+
/** The consent box's id and look (`classNames` for its `CheckboxSlot`s). */
|
|
50
|
+
readonly consentProps?: ConsentProps;
|
|
38
51
|
/**
|
|
39
52
|
* The app's own inputs, before the consent checkbox. Their values reach `onRegistered` as
|
|
40
53
|
* `event.fields` when their names are declared in `auth({ registrationFields })`.
|
|
41
54
|
*/
|
|
42
55
|
readonly extraFields?: ReactNode;
|
|
43
56
|
}
|
|
44
|
-
export declare function RegisterForm(
|
|
57
|
+
export declare function RegisterForm(props: RegisterFormProps): import("react").JSX.Element;
|
|
45
58
|
export interface ChangePasswordFormProps extends AuthFormBaseProps {
|
|
46
59
|
readonly minPasswordLength: number;
|
|
47
60
|
}
|
|
48
|
-
export declare function ChangePasswordForm(
|
|
61
|
+
export declare function ChangePasswordForm(props: ChangePasswordFormProps): import("react").JSX.Element;
|
|
49
62
|
export interface ForgotPasswordFormProps extends AuthFormBaseProps {
|
|
50
63
|
/** How long a link works, for the confirmation. */
|
|
51
64
|
readonly ttlMinutes: number;
|
|
52
65
|
readonly loginHref?: string;
|
|
53
66
|
}
|
|
54
67
|
/** Asks for a reset link. Its confirmation is the same whether or not the email has an account. */
|
|
55
|
-
export declare function ForgotPasswordForm(
|
|
68
|
+
export declare function ForgotPasswordForm(props: ForgotPasswordFormProps): import("react").JSX.Element;
|
|
56
69
|
export interface ResetPasswordFormProps extends AuthFormBaseProps {
|
|
57
70
|
/** The token from the reset link; checked again on the server. */
|
|
58
71
|
readonly token: string;
|
|
59
72
|
readonly minPasswordLength: number;
|
|
60
73
|
}
|
|
61
74
|
/** Sets a new password from a reset link; its action goes to the login page on success. */
|
|
62
|
-
export declare function ResetPasswordForm(
|
|
75
|
+
export declare function ResetPasswordForm(props: ResetPasswordFormProps): import("react").JSX.Element;
|
|
63
76
|
export {};
|
|
64
77
|
//# sourceMappingURL=auth-forms.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-forms.d.ts","sourceRoot":"","sources":["../../src/ui/auth-forms.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,kB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,uBAAuB,+BA0ChE;AAED,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,mGAAmG;AACnG,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,+BAgDhE;AAED,MAAM,WAAW,sBAAuB,SAAQ,iBAAiB;IAC/D,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED,2FAA2F;AAC3F,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,+BA6B9D"}
|
package/dist/ui/auth-forms.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { formatMessage } from "@softure-ai/core";
|
|
4
|
-
import { Button, Checkbox, createSlotClassGetter, FormError, PasswordField, TextField } from "@softure-ai/ui";
|
|
5
|
-
import { useActionState } from "react";
|
|
4
|
+
import { Button, Checkbox, createSlotClassGetter, FormError, PasswordField, TextField, } from "@softure-ai/ui";
|
|
5
|
+
import { useActionState, useState } from "react";
|
|
6
6
|
import { INITIAL_AUTH_FORM_STATE } from "../contract.js";
|
|
7
7
|
import { getAuthErrorMessage } from "../messages/index.js";
|
|
8
|
+
/** The field props every form passes to each of its text and password fields. */
|
|
9
|
+
function getFieldLook({ fieldClassNames, fieldHintAs, fieldHintProps, unstyled, locale }) {
|
|
10
|
+
return { classNames: fieldClassNames, hintAs: fieldHintAs, hintProps: fieldHintProps, unstyled, locale };
|
|
11
|
+
}
|
|
8
12
|
const DEFAULT_CLASSES = {
|
|
9
13
|
root: "sft:flex sft:flex-col sft:gap-3 sft:font-sans",
|
|
10
14
|
form: "sft:flex sft:flex-col sft:gap-3",
|
|
@@ -14,54 +18,94 @@ const DEFAULT_CLASSES = {
|
|
|
14
18
|
// The button styles itself; the slot only carries the app's class.
|
|
15
19
|
submit: "",
|
|
16
20
|
};
|
|
17
|
-
/**
|
|
18
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The error of one field, or of the form when no field owns it or the form does not render that field
|
|
23
|
+
* (e.g. `consent` with the box left out), so a server error is never dropped.
|
|
24
|
+
*/
|
|
25
|
+
function useErrors(state, messages, renderedFields) {
|
|
19
26
|
const message = state.error === undefined ? undefined : getAuthErrorMessage(messages, state.error);
|
|
27
|
+
const isFieldRendered = state.field !== undefined && renderedFields.includes(state.field);
|
|
20
28
|
return {
|
|
21
29
|
at: (field) => (state.field === field ? message : undefined),
|
|
22
|
-
form:
|
|
30
|
+
form: isFieldRendered ? undefined : message,
|
|
23
31
|
};
|
|
24
32
|
}
|
|
33
|
+
/** The first control of `form` that fails its constraints, in document order. */
|
|
34
|
+
function getFirstInvalidControl(form) {
|
|
35
|
+
return Array.from(form.elements).find((element) => (element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) &&
|
|
36
|
+
!element.validity.valid);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A required consent box. An unticked box shows `requiredMessage` under it instead of the browser's bubble (as ui's
|
|
40
|
+
* `CheckboxField` in statement mode does) and takes focus when it is the form's first invalid control; the server's
|
|
41
|
+
* error shows there otherwise.
|
|
42
|
+
*/
|
|
43
|
+
function ConsentCheckbox({ label, requiredMessage, error, consentProps, unstyled, }) {
|
|
44
|
+
const [invalidMessage, setInvalidMessage] = useState(undefined);
|
|
45
|
+
function handleInvalid(event) {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
setInvalidMessage(requiredMessage);
|
|
48
|
+
const box = event.currentTarget;
|
|
49
|
+
const firstInvalid = box.form === null ? box : getFirstInvalidControl(box.form);
|
|
50
|
+
if (firstInvalid === box)
|
|
51
|
+
box.focus();
|
|
52
|
+
}
|
|
53
|
+
return (_jsx(Checkbox, { id: consentProps?.id, classNames: consentProps?.classNames, name: "consent", label: label, required: true, error: invalidMessage ?? error, onInvalid: handleInvalid, onChange: (event) => {
|
|
54
|
+
if (event.currentTarget.checked)
|
|
55
|
+
setInvalidMessage(undefined);
|
|
56
|
+
}, unstyled: unstyled }));
|
|
57
|
+
}
|
|
25
58
|
function FormShell({ formAction, isPending, submitLabel, pendingLabel, formError, footer, slot, unstyled, submitVariant = "primary", children, }) {
|
|
26
59
|
return (_jsxs("div", { className: slot("root"), children: [_jsxs("form", { action: formAction, className: slot("form"), children: [children, _jsx(FormError, { message: formError, unstyled: unstyled }), _jsx(Button, { type: "submit", variant: submitVariant, fullWidth: true, pending: isPending, classNames: { root: slot("submit") }, unstyled: unstyled, children: isPending ? pendingLabel : submitLabel })] }), footer] }));
|
|
27
60
|
}
|
|
28
|
-
export function LoginForm(
|
|
61
|
+
export function LoginForm(props) {
|
|
62
|
+
const { action, messages, next, registerHref, forgotPasswordHref, notice, classNames, unstyled, submitVariant } = props;
|
|
29
63
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
30
|
-
const errors = useErrors(state, messages);
|
|
64
|
+
const errors = useErrors(state, messages, ["email", "password"]);
|
|
65
|
+
const field = getFieldLook(props);
|
|
31
66
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
32
67
|
const footer = registerHref === undefined && forgotPasswordHref === undefined && notice === undefined ? undefined : (_jsxs(_Fragment, { children: [notice === undefined ? null : (_jsx("p", { role: "status", className: slot("notice"), children: notice })), forgotPasswordHref === undefined ? null : (_jsx("p", { className: slot("footer"), children: _jsx("a", { href: forgotPasswordHref, className: slot("link"), children: messages.login.forgotPassword }) })), registerHref === undefined ? null : (_jsxs("p", { className: slot("footer"), children: [messages.login.noAccount, " ", _jsx("a", { href: registerHref, className: slot("link"), children: messages.login.registerLink })] }))] }));
|
|
33
|
-
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.login.submit, pendingLabel: messages.login.pending, formError: errors.form, footer: footer, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: [next === undefined ? null : _jsx("input", { type: "hidden", name: "next", value: next }), _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"),
|
|
68
|
+
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.login.submit, pendingLabel: messages.login.pending, formError: errors.form, footer: footer, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: [next === undefined ? null : _jsx("input", { type: "hidden", name: "next", value: next }), _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"), ...field }), _jsx(PasswordField, { name: "password", label: messages.fields.password, autoComplete: "current-password", error: errors.at("password"), ...field })] }));
|
|
34
69
|
}
|
|
35
|
-
export function RegisterForm(
|
|
70
|
+
export function RegisterForm(props) {
|
|
71
|
+
const { action, messages, next, loginHref, requireConsent, minPasswordLength, consentLabel, consentProps, extraFields } = props;
|
|
72
|
+
const { classNames, unstyled, submitVariant } = props;
|
|
36
73
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
37
|
-
const errors = useErrors(state, messages);
|
|
74
|
+
const errors = useErrors(state, messages, requireConsent ? ["email", "password", "consent"] : ["email", "password"]);
|
|
75
|
+
const field = getFieldLook(props);
|
|
38
76
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
39
77
|
const footer = loginHref === undefined ? undefined : (_jsxs("p", { className: slot("footer"), children: [messages.register.hasAccount, " ", _jsx("a", { href: loginHref, className: slot("link"), children: messages.register.loginLink })] }));
|
|
40
|
-
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.register.submit, pendingLabel: messages.register.pending, formError: errors.form, footer: footer, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: [next === undefined ? null : _jsx("input", { type: "hidden", name: "next", value: next }), _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"),
|
|
78
|
+
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.register.submit, pendingLabel: messages.register.pending, formError: errors.form, footer: footer, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: [next === undefined ? null : _jsx("input", { type: "hidden", name: "next", value: next }), _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"), ...field }), _jsx(PasswordField, { name: "password", label: messages.fields.password, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("password"), ...field }), extraFields, requireConsent ? (_jsx(ConsentCheckbox, { label: consentLabel ?? messages.fields.consent, requiredMessage: messages.errors.auth.consent_required, error: errors.at("consent"), consentProps: consentProps, unstyled: unstyled })) : null] }));
|
|
41
79
|
}
|
|
42
|
-
export function ChangePasswordForm(
|
|
80
|
+
export function ChangePasswordForm(props) {
|
|
81
|
+
const { action, messages, minPasswordLength, classNames, unstyled, submitVariant } = props;
|
|
43
82
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
44
|
-
const errors = useErrors(state, messages);
|
|
83
|
+
const errors = useErrors(state, messages, ["currentPassword", "newPassword"]);
|
|
84
|
+
const field = getFieldLook(props);
|
|
45
85
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
46
86
|
const notice = state.status === "ok" ? (_jsx("p", { role: "status", className: slot("notice"), children: messages.changePassword.success })) : undefined;
|
|
47
|
-
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.changePassword.submit, pendingLabel: messages.changePassword.pending, formError: errors.form, footer: notice, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: [_jsx(PasswordField, { name: "currentPassword", label: messages.fields.currentPassword, autoComplete: "current-password", error: errors.at("currentPassword"),
|
|
87
|
+
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.changePassword.submit, pendingLabel: messages.changePassword.pending, formError: errors.form, footer: notice, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: [_jsx(PasswordField, { name: "currentPassword", label: messages.fields.currentPassword, autoComplete: "current-password", error: errors.at("currentPassword"), ...field }), _jsx(PasswordField, { name: "newPassword", label: messages.fields.newPassword, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("newPassword"), ...field })] }));
|
|
48
88
|
}
|
|
49
89
|
/** Asks for a reset link. Its confirmation is the same whether or not the email has an account. */
|
|
50
|
-
export function ForgotPasswordForm(
|
|
90
|
+
export function ForgotPasswordForm(props) {
|
|
91
|
+
const { action, messages, ttlMinutes, loginHref, classNames, unstyled, submitVariant } = props;
|
|
51
92
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
52
|
-
const errors = useErrors(state, messages);
|
|
93
|
+
const errors = useErrors(state, messages, ["email"]);
|
|
94
|
+
const field = getFieldLook(props);
|
|
53
95
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
54
96
|
const backToLogin = loginHref === undefined ? undefined : (_jsx("p", { className: slot("footer"), children: _jsx("a", { href: loginHref, className: slot("link"), children: messages.forgotPassword.backToLogin }) }));
|
|
55
97
|
if (state.status === "ok") {
|
|
56
98
|
return (_jsxs("div", { className: slot("root"), children: [_jsx("p", { role: "status", className: slot("notice"), children: formatMessage(messages.forgotPassword.sent, { ttlMinutes }) }), backToLogin] }));
|
|
57
99
|
}
|
|
58
|
-
return (_jsx(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.forgotPassword.submit, pendingLabel: messages.forgotPassword.pending, formError: errors.form, footer: backToLogin, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"),
|
|
100
|
+
return (_jsx(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.forgotPassword.submit, pendingLabel: messages.forgotPassword.pending, formError: errors.form, footer: backToLogin, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: _jsx(TextField, { name: "email", type: "email", label: messages.fields.email, autoComplete: "email", required: true, defaultValue: state.email ?? "", error: errors.at("email"), ...field }) }));
|
|
59
101
|
}
|
|
60
102
|
/** Sets a new password from a reset link; its action goes to the login page on success. */
|
|
61
|
-
export function ResetPasswordForm(
|
|
103
|
+
export function ResetPasswordForm(props) {
|
|
104
|
+
const { action, messages, token, minPasswordLength, classNames, unstyled, submitVariant } = props;
|
|
62
105
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
63
|
-
const errors = useErrors(state, messages);
|
|
106
|
+
const errors = useErrors(state, messages, ["newPassword"]);
|
|
107
|
+
const field = getFieldLook(props);
|
|
64
108
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
65
|
-
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.resetPassword.submit, pendingLabel: messages.resetPassword.pending, formError: errors.form, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: [_jsx("input", { type: "hidden", name: "token", value: token }), _jsx(PasswordField, { name: "newPassword", label: messages.fields.newPassword, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("newPassword"),
|
|
109
|
+
return (_jsxs(FormShell, { formAction: formAction, isPending: isPending, submitLabel: messages.resetPassword.submit, pendingLabel: messages.resetPassword.pending, formError: errors.form, slot: slot, unstyled: unstyled, submitVariant: submitVariant, children: [_jsx("input", { type: "hidden", name: "token", value: token }), _jsx(PasswordField, { name: "newPassword", label: messages.fields.newPassword, hint: formatMessage(messages.fields.newPasswordHint, { minLength: minPasswordLength }), autoComplete: "new-password", minLength: minPasswordLength, error: errors.at("newPassword"), ...field })] }));
|
|
66
110
|
}
|
|
67
111
|
//# sourceMappingURL=auth-forms.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-forms.js","sourceRoot":"","sources":["../../src/ui/auth-forms.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,aAAa,EAAe,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAsB,QAAQ,EAAmB,qBAAqB,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACnJ,OAAO,EAAkB,cAAc,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAA0C,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAqB,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAqB9E,MAAM,eAAe,GAA2C;IAC9D,IAAI,EAAE,+CAA+C;IACrD,IAAI,EAAE,iCAAiC;IACvC,MAAM,EAAE,oCAAoC;IAC5C,IAAI,EAAE,iCAAiC;IACvC,MAAM,EAAE,sCAAsC;IAC9C,mEAAmE;IACnE,MAAM,EAAE,EAAE;CACX,CAAC;AAEF,oEAAoE;AACpE,SAAS,SAAS,CAAC,KAAoB,EAAE,QAAsB;IAC7D,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,mBAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACnG,OAAO;QACL,EAAE,EAAE,CAAC,KAAoB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3E,IAAI,EAAE,KAAK,CA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AC,QAAQ,EAAC,IAAI,EAAC,OAAO,EAAC,KAAK,EAAE,KAAK,GAAI,EAClD,KAAC,aAAa,IACZ,IAAI,EAAC,aAAa,EAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAClC,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC,EACtF,YAAY,EAAC,cAAc,EAC3B,SAAS,EAAE,iBAAiB,EAC5B,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC,KAC3B,KAAK,GACT,IACQ,CACb,CAAC;AACJ,CAAC"}
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { type AuthFormAction, type AuthFormSlot, ChangePasswordForm, type ChangePasswordFormProps, ForgotPasswordForm, type ForgotPasswordFormProps, LoginForm, type LoginFormProps, RegisterForm, type RegisterFormProps, ResetPasswordForm, type ResetPasswordFormProps, } from "./auth-forms.js";
|
|
1
|
+
export { type AuthFormAction, type AuthFormSlot, ChangePasswordForm, type ChangePasswordFormProps, type ConsentProps, ForgotPasswordForm, type ForgotPasswordFormProps, LoginForm, type LoginFormProps, RegisterForm, type RegisterFormProps, ResetPasswordForm, type ResetPasswordFormProps, } from "./auth-forms.js";
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/ui/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,SAAS,EACT,KAAK,cAAc,EACnB,YAAY,EACZ,KAAK,iBAAiB,EACtB,iBAAiB,EACjB,KAAK,sBAAsB,GAC5B,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,SAAS,EACT,KAAK,cAAc,EACnB,YAAY,EACZ,KAAK,iBAAiB,EACtB,iBAAiB,EACjB,KAAK,sBAAsB,GAC5B,MAAM,iBAAiB,CAAC"}
|
package/dist/ui/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,6FAA6F;AAC7F,OAAO,EAGL,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,6FAA6F;AAC7F,OAAO,EAGL,kBAAkB,EAGlB,kBAAkB,EAElB,SAAS,EAET,YAAY,EAEZ,iBAAiB,GAElB,MAAM,iBAAiB,CAAC"}
|
package/module.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softure-ai/auth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "SOFTURE AI auth module: users, scrypt passwords, database sessions, register with consent, login, logout, password change, roles, a proxy route guard, pages and forms for Next.js, and a password reset sender over @softure-ai/mailing, sent in the request or by a background job through @softure-ai/jobs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/index.ts
CHANGED
|
@@ -42,7 +42,7 @@ export const AUTH_RATE_LIMIT_BUCKETS = {
|
|
|
42
42
|
export const auth = defineModule({
|
|
43
43
|
manifest: {
|
|
44
44
|
id: MODULE_ID,
|
|
45
|
-
version: "0.2.
|
|
45
|
+
version: "0.2.4",
|
|
46
46
|
dependsOn: { security: "^0.2.0", mailing: "^0.2.0?", ops: "^0.2.0?", jobs: "^0.1.1?" },
|
|
47
47
|
dbSchema: "auth",
|
|
48
48
|
tables: ["users", "sessions", "user_roles", "password_resets"],
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// The first account of an app whose registration is closed: a safe ops script
|
|
2
|
+
// (`@softure-ai/ops/scripts`), dry run by default, `--commit` writes. It creates the account with a
|
|
3
|
+
// drawn temporary password, printed once, or with a `hashPassword` hash computed elsewhere
|
|
4
|
+
// (`--password-hash`, best through `--password-hash-file=-`). With `maxAccounts` it refuses once the
|
|
5
|
+
// table holds that many accounts; the table is locked for the run, so two runs cannot both pass.
|
|
6
|
+
// The app's `onRegistered` hook does not run: nobody gave consent and there are no registration
|
|
7
|
+
// fields. Reports carry the user id, never the email or the hash.
|
|
8
|
+
import { ok, systemClock, type Clock, type SoftureConfig } from "@softure-ai/core";
|
|
9
|
+
import { defineOpsScript, refuseOpsScript, type OpsScript } from "@softure-ai/ops/scripts";
|
|
10
|
+
import { count, sql } from "drizzle-orm";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { users } from "../schema.js";
|
|
13
|
+
import { parseEmail } from "../server/validation.js";
|
|
14
|
+
import { choosePassword, describeChosenPassword, PASSWORD_HASH_KEY, PASSWORD_HASH_USAGE, passwordHashArg } from "./password-choice.js";
|
|
15
|
+
|
|
16
|
+
export interface CreateAccountScriptArgs {
|
|
17
|
+
readonly email: string;
|
|
18
|
+
/** A hash from `hashPassword`, computed where the password was made; the script then draws none. */
|
|
19
|
+
readonly "password-hash"?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CreateAccountScriptOptions {
|
|
23
|
+
/** The time stored as `created_at` and `password_changed_at`; the system clock by default. */
|
|
24
|
+
readonly clock?: Clock;
|
|
25
|
+
/** The characters a drawn password uses (e.g. `READABLE_PASSWORD_ALPHABET`); base64url by default. */
|
|
26
|
+
readonly alphabet?: string;
|
|
27
|
+
/** The most accounts the app holds (e.g. 1 for a single-owner app); the script refuses beyond it. No limit by default. */
|
|
28
|
+
readonly maxAccounts?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const scriptArgs = z.strictObject({
|
|
32
|
+
email: z.string().min(1, "--email=<account email> is required"),
|
|
33
|
+
[PASSWORD_HASH_KEY]: passwordHashArg,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** `create-account --email=… [--password-hash=…]`: a new account, with or without registration open. */
|
|
37
|
+
export function createCreateAccountScript(config: SoftureConfig, options: CreateAccountScriptOptions = {}): OpsScript<CreateAccountScriptArgs> {
|
|
38
|
+
const { maxAccounts } = options;
|
|
39
|
+
if (maxAccounts !== undefined && !(Number.isInteger(maxAccounts) && maxAccounts >= 1)) {
|
|
40
|
+
throw new Error("@softure-ai/auth: createCreateAccountScript needs maxAccounts to be a whole number of at least 1");
|
|
41
|
+
}
|
|
42
|
+
const clock = options.clock ?? systemClock;
|
|
43
|
+
return defineOpsScript({
|
|
44
|
+
name: "create-account",
|
|
45
|
+
description: "Creates an account with the given email and a random password (or the given hash), also while registration is closed.",
|
|
46
|
+
usage: ["--email=<account email>", PASSWORD_HASH_USAGE],
|
|
47
|
+
args: scriptArgs,
|
|
48
|
+
secrets: [PASSWORD_HASH_KEY],
|
|
49
|
+
run: async (tx, args) => {
|
|
50
|
+
const email = parseEmail(args.email);
|
|
51
|
+
if (!email.ok) return refuseOpsScript("the email is not valid");
|
|
52
|
+
// Conflicts with itself and with every insert, until the script's transaction ends.
|
|
53
|
+
await tx.execute(sql`LOCK TABLE auth.users IN SHARE ROW EXCLUSIVE MODE`);
|
|
54
|
+
const [counted] = await tx.select({ accounts: count() }).from(users);
|
|
55
|
+
const accounts = counted?.accounts ?? 0;
|
|
56
|
+
if (maxAccounts !== undefined && accounts >= maxAccounts) {
|
|
57
|
+
return refuseOpsScript(`the app already holds ${String(accounts)} account(s), its maxAccounts`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const password = await choosePassword(args[PASSWORD_HASH_KEY], config, options.alphabet);
|
|
61
|
+
const now = clock.now();
|
|
62
|
+
const [created] = await tx
|
|
63
|
+
.insert(users)
|
|
64
|
+
.values({ email: email.value, passwordHash: password.hash, createdAt: now, passwordChangedAt: now })
|
|
65
|
+
.onConflictDoNothing({ target: users.email })
|
|
66
|
+
.returning({ id: users.id });
|
|
67
|
+
if (created === undefined) return refuseOpsScript("an account with this email already exists");
|
|
68
|
+
return ok({ before: { accounts }, after: { userId: created.id, accounts: accounts + 1, ...describeChosenPassword(password) } });
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
package/src/scripts/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// `@softure-ai/auth/scripts`: ops scripts that grant and revoke roles
|
|
2
|
-
// and the development seed account
|
|
3
|
-
// (see the README, "Roles", "Account recovery" and "Development seed").
|
|
1
|
+
// `@softure-ai/auth/scripts`: ops scripts that grant and revoke roles, set a temporary password and
|
|
2
|
+
// create an account, and the development seed account
|
|
3
|
+
// (see the README, "Roles", "Account recovery", "First account" and "Development seed").
|
|
4
4
|
export { createGrantRoleScript, createRevokeRoleScript, type RoleScriptArgs, type RoleScriptOptions } from "./role-scripts.js";
|
|
5
5
|
export {
|
|
6
6
|
createSetTemporaryPasswordScript,
|
|
7
7
|
type TemporaryPasswordScriptArgs,
|
|
8
8
|
type TemporaryPasswordScriptOptions,
|
|
9
9
|
} from "./temporary-password.js";
|
|
10
|
+
export { createCreateAccountScript, type CreateAccountScriptArgs, type CreateAccountScriptOptions } from "./create-account.js";
|
|
10
11
|
export { runSeedAccount, type RunSeedAccountOptions } from "./seed-account.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The password an ops script stores: a drawn temporary one, or a `hashPassword` hash computed where
|
|
2
|
+
// the password was made (`--password-hash`, best through `--password-hash-file=-`), so the plain
|
|
3
|
+
// password never reaches the server. Shared by `set-temporary-password` and `create-account`.
|
|
4
|
+
import type { SoftureConfig } from "@softure-ai/core";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { getAuthOptions } from "../server/options.js";
|
|
7
|
+
import { hashPassword, isPasswordHash } from "../server/password.js";
|
|
8
|
+
import { createTemporaryPassword } from "../server/temporary-password.js";
|
|
9
|
+
|
|
10
|
+
/** Long enough to be out of guessing range in any rate limit window. */
|
|
11
|
+
const MIN_TEMPORARY_LENGTH = 20;
|
|
12
|
+
export const PASSWORD_HASH_KEY = "password-hash";
|
|
13
|
+
export const PASSWORD_HASH_USAGE = `--${PASSWORD_HASH_KEY}=<hash> store this hashPassword() hash instead of drawing a password`;
|
|
14
|
+
|
|
15
|
+
// A constant message: the value is secret-derived and must not be echoed.
|
|
16
|
+
export const passwordHashArg = z.string().refine(isPasswordHash, "is not a scrypt hash written by @softure-ai/auth").optional();
|
|
17
|
+
|
|
18
|
+
export type ChosenPassword =
|
|
19
|
+
| { readonly from: "hash"; readonly hash: string }
|
|
20
|
+
| { readonly from: "drawn"; readonly hash: string; readonly plain: string };
|
|
21
|
+
|
|
22
|
+
/** The given hash, or a drawn password of at least 20 characters and `password.minLength`, with its hash. */
|
|
23
|
+
export async function choosePassword(givenHash: string | undefined, config: SoftureConfig, alphabet: string | undefined): Promise<ChosenPassword> {
|
|
24
|
+
if (givenHash !== undefined) return { from: "hash", hash: givenHash };
|
|
25
|
+
const { password } = getAuthOptions(config);
|
|
26
|
+
const plain = createTemporaryPassword({ alphabet, length: Math.max(password.minLength, MIN_TEMPORARY_LENGTH) });
|
|
27
|
+
return { from: "drawn", hash: await hashPassword(plain, password.scrypt), plain };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** What a report says about the stored password: never the hash, the drawn password once. */
|
|
31
|
+
export function describeChosenPassword(password: ChosenPassword): { passwordFrom: "hash" } | { temporaryPassword: string } {
|
|
32
|
+
return password.from === "hash" ? { passwordFrom: "hash" } : { temporaryPassword: password.plain };
|
|
33
|
+
}
|
|
@@ -10,15 +10,9 @@ import { defineOpsScript, refuseOpsScript, type OpsScript } from "@softure-ai/op
|
|
|
10
10
|
import { eq } from "drizzle-orm";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { passwordResets, sessions, users } from "../schema.js";
|
|
13
|
-
import { getAuthOptions } from "../server/options.js";
|
|
14
|
-
import { hashPassword, isPasswordHash } from "../server/password.js";
|
|
15
13
|
import { revokeUserSessions, type AuthContext } from "../server/sessions.js";
|
|
16
|
-
import { createTemporaryPassword } from "../server/temporary-password.js";
|
|
17
14
|
import { normalizeEmail } from "../server/validation.js";
|
|
18
|
-
|
|
19
|
-
/** Long enough to be out of guessing range in any rate limit window. */
|
|
20
|
-
const MIN_TEMPORARY_LENGTH = 20;
|
|
21
|
-
const PASSWORD_HASH_KEY = "password-hash";
|
|
15
|
+
import { choosePassword, describeChosenPassword, PASSWORD_HASH_KEY, PASSWORD_HASH_USAGE, passwordHashArg } from "./password-choice.js";
|
|
22
16
|
|
|
23
17
|
export interface TemporaryPasswordScriptArgs {
|
|
24
18
|
readonly email: string;
|
|
@@ -35,8 +29,7 @@ export interface TemporaryPasswordScriptOptions {
|
|
|
35
29
|
|
|
36
30
|
const scriptArgs = z.strictObject({
|
|
37
31
|
email: z.string().min(1, "--email=<account email> is required"),
|
|
38
|
-
|
|
39
|
-
[PASSWORD_HASH_KEY]: z.string().refine(isPasswordHash, "is not a scrypt hash written by @softure-ai/auth").optional(),
|
|
32
|
+
[PASSWORD_HASH_KEY]: passwordHashArg,
|
|
40
33
|
});
|
|
41
34
|
|
|
42
35
|
/** `set-temporary-password --email=… [--password-hash=…]`: a new password, every session and reset link ended. */
|
|
@@ -49,7 +42,7 @@ export function createSetTemporaryPasswordScript(
|
|
|
49
42
|
name: "set-temporary-password",
|
|
50
43
|
description:
|
|
51
44
|
"Sets a new password for the account with the given email (a random one, or the given hash) and ends its sessions and reset link.",
|
|
52
|
-
usage: ["--email=<account email>",
|
|
45
|
+
usage: ["--email=<account email>", PASSWORD_HASH_USAGE],
|
|
53
46
|
args: scriptArgs,
|
|
54
47
|
secrets: [PASSWORD_HASH_KEY],
|
|
55
48
|
run: async (tx, args) => {
|
|
@@ -63,18 +56,7 @@ export function createSetTemporaryPasswordScript(
|
|
|
63
56
|
await revokeUserSessions(ctx, account.id);
|
|
64
57
|
await tx.delete(passwordResets).where(eq(passwordResets.userId, account.id));
|
|
65
58
|
const remaining = (await tx.select().from(sessions).where(eq(sessions.userId, account.id))).length;
|
|
66
|
-
|
|
67
|
-
return ok({ before, after: { userId: account.id, sessions: remaining, ...after } });
|
|
59
|
+
return ok({ before, after: { userId: account.id, sessions: remaining, ...describeChosenPassword(password) } });
|
|
68
60
|
},
|
|
69
61
|
});
|
|
70
62
|
}
|
|
71
|
-
|
|
72
|
-
type ChosenPassword = { readonly from: "hash"; readonly hash: string } | { readonly from: "drawn"; readonly hash: string; readonly plain: string };
|
|
73
|
-
|
|
74
|
-
/** The given hash, or a drawn password of at least 20 characters and `password.minLength`, with its hash. */
|
|
75
|
-
async function choosePassword(givenHash: string | undefined, config: SoftureConfig, alphabet: string | undefined): Promise<ChosenPassword> {
|
|
76
|
-
if (givenHash !== undefined) return { from: "hash", hash: givenHash };
|
|
77
|
-
const { password } = getAuthOptions(config);
|
|
78
|
-
const plain = createTemporaryPassword({ alphabet, length: Math.max(password.minLength, MIN_TEMPORARY_LENGTH) });
|
|
79
|
-
return { from: "drawn", hash: await hashPassword(plain, password.scrypt), plain };
|
|
80
|
-
}
|
package/src/ui/auth-forms.tsx
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { formatMessage, type Locale } from "@softure-ai/core";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
type ButtonVariant,
|
|
7
|
+
Checkbox,
|
|
8
|
+
type CheckboxSlot,
|
|
9
|
+
type ClassNames,
|
|
10
|
+
createSlotClassGetter,
|
|
11
|
+
FormError,
|
|
12
|
+
type HintAppearance,
|
|
13
|
+
type HintPlacement,
|
|
14
|
+
type InputFieldSlot,
|
|
15
|
+
PasswordField,
|
|
16
|
+
TextField,
|
|
17
|
+
} from "@softure-ai/ui";
|
|
18
|
+
import { type InvalidEvent, type ReactNode, useActionState, useState } from "react";
|
|
6
19
|
import { type AuthFormField, type AuthFormState, INITIAL_AUTH_FORM_STATE } from "../contract.js";
|
|
7
20
|
import { type AuthMessages, getAuthErrorMessage } from "../messages/index.js";
|
|
8
21
|
|
|
@@ -23,6 +36,17 @@ interface AuthFormBaseProps {
|
|
|
23
36
|
readonly unstyled?: boolean;
|
|
24
37
|
/** The submit button's look; `primary` by default. Its class goes in `classNames.submit`. */
|
|
25
38
|
readonly submitVariant?: ButtonVariant;
|
|
39
|
+
/** Classes for every text and password field of the form (label, hint, input, ...), to match the app's other forms. */
|
|
40
|
+
readonly fieldClassNames?: ClassNames<InputFieldSlot>;
|
|
41
|
+
/** Where the fields show their hints: under the label (default) or behind a "?" tooltip. */
|
|
42
|
+
readonly fieldHintAs?: HintPlacement;
|
|
43
|
+
/** The tooltip hint's look for every field, so it matches the app's standalone hints. */
|
|
44
|
+
readonly fieldHintProps?: HintAppearance;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The field props every form passes to each of its text and password fields. */
|
|
48
|
+
function getFieldLook({ fieldClassNames, fieldHintAs, fieldHintProps, unstyled, locale }: AuthFormBaseProps) {
|
|
49
|
+
return { classNames: fieldClassNames, hintAs: fieldHintAs, hintProps: fieldHintProps, unstyled, locale };
|
|
26
50
|
}
|
|
27
51
|
|
|
28
52
|
const DEFAULT_CLASSES: Readonly<Record<AuthFormSlot, string>> = {
|
|
@@ -35,15 +59,77 @@ const DEFAULT_CLASSES: Readonly<Record<AuthFormSlot, string>> = {
|
|
|
35
59
|
submit: "",
|
|
36
60
|
};
|
|
37
61
|
|
|
38
|
-
/**
|
|
39
|
-
|
|
62
|
+
/**
|
|
63
|
+
* The error of one field, or of the form when no field owns it or the form does not render that field
|
|
64
|
+
* (e.g. `consent` with the box left out), so a server error is never dropped.
|
|
65
|
+
*/
|
|
66
|
+
function useErrors(state: AuthFormState, messages: AuthMessages, renderedFields: readonly AuthFormField[]) {
|
|
40
67
|
const message = state.error === undefined ? undefined : getAuthErrorMessage(messages, state.error);
|
|
68
|
+
const isFieldRendered = state.field !== undefined && renderedFields.includes(state.field);
|
|
41
69
|
return {
|
|
42
70
|
at: (field: AuthFormField) => (state.field === field ? message : undefined),
|
|
43
|
-
form:
|
|
71
|
+
form: isFieldRendered ? undefined : message,
|
|
44
72
|
};
|
|
45
73
|
}
|
|
46
74
|
|
|
75
|
+
/** The consent box's own props: its id (e.g. for the app's tests) and its look. */
|
|
76
|
+
export interface ConsentProps {
|
|
77
|
+
readonly id?: string;
|
|
78
|
+
readonly classNames?: ClassNames<CheckboxSlot>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The first control of `form` that fails its constraints, in document order. */
|
|
82
|
+
function getFirstInvalidControl(form: HTMLFormElement): Element | undefined {
|
|
83
|
+
return Array.from(form.elements).find(
|
|
84
|
+
(element) =>
|
|
85
|
+
(element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) &&
|
|
86
|
+
!element.validity.valid,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A required consent box. An unticked box shows `requiredMessage` under it instead of the browser's bubble (as ui's
|
|
92
|
+
* `CheckboxField` in statement mode does) and takes focus when it is the form's first invalid control; the server's
|
|
93
|
+
* error shows there otherwise.
|
|
94
|
+
*/
|
|
95
|
+
function ConsentCheckbox({
|
|
96
|
+
label,
|
|
97
|
+
requiredMessage,
|
|
98
|
+
error,
|
|
99
|
+
consentProps,
|
|
100
|
+
unstyled,
|
|
101
|
+
}: {
|
|
102
|
+
label: ReactNode;
|
|
103
|
+
requiredMessage: string;
|
|
104
|
+
error: string | undefined;
|
|
105
|
+
consentProps: ConsentProps | undefined;
|
|
106
|
+
unstyled: boolean | undefined;
|
|
107
|
+
}) {
|
|
108
|
+
const [invalidMessage, setInvalidMessage] = useState<string | undefined>(undefined);
|
|
109
|
+
function handleInvalid(event: InvalidEvent<HTMLInputElement>) {
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
setInvalidMessage(requiredMessage);
|
|
112
|
+
const box = event.currentTarget;
|
|
113
|
+
const firstInvalid = box.form === null ? box : getFirstInvalidControl(box.form);
|
|
114
|
+
if (firstInvalid === box) box.focus();
|
|
115
|
+
}
|
|
116
|
+
return (
|
|
117
|
+
<Checkbox
|
|
118
|
+
id={consentProps?.id}
|
|
119
|
+
classNames={consentProps?.classNames}
|
|
120
|
+
name="consent"
|
|
121
|
+
label={label}
|
|
122
|
+
required
|
|
123
|
+
error={invalidMessage ?? error}
|
|
124
|
+
onInvalid={handleInvalid}
|
|
125
|
+
onChange={(event) => {
|
|
126
|
+
if (event.currentTarget.checked) setInvalidMessage(undefined);
|
|
127
|
+
}}
|
|
128
|
+
unstyled={unstyled}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
47
133
|
function FormShell({
|
|
48
134
|
formAction,
|
|
49
135
|
isPending,
|
|
@@ -92,9 +178,11 @@ export interface LoginFormProps extends AuthFormBaseProps {
|
|
|
92
178
|
readonly notice?: string;
|
|
93
179
|
}
|
|
94
180
|
|
|
95
|
-
export function LoginForm(
|
|
181
|
+
export function LoginForm(props: LoginFormProps) {
|
|
182
|
+
const { action, messages, next, registerHref, forgotPasswordHref, notice, classNames, unstyled, submitVariant } = props;
|
|
96
183
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
97
|
-
const errors = useErrors(state, messages);
|
|
184
|
+
const errors = useErrors(state, messages, ["email", "password"]);
|
|
185
|
+
const field = getFieldLook(props);
|
|
98
186
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
99
187
|
const footer =
|
|
100
188
|
registerHref === undefined && forgotPasswordHref === undefined && notice === undefined ? undefined : (
|
|
@@ -142,16 +230,14 @@ export function LoginForm({ action, messages, locale, next, registerHref, forgot
|
|
|
142
230
|
required
|
|
143
231
|
defaultValue={state.email ?? ""}
|
|
144
232
|
error={errors.at("email")}
|
|
145
|
-
|
|
146
|
-
locale={locale}
|
|
233
|
+
{...field}
|
|
147
234
|
/>
|
|
148
235
|
<PasswordField
|
|
149
236
|
name="password"
|
|
150
237
|
label={messages.fields.password}
|
|
151
238
|
autoComplete="current-password"
|
|
152
239
|
error={errors.at("password")}
|
|
153
|
-
|
|
154
|
-
locale={locale}
|
|
240
|
+
{...field}
|
|
155
241
|
/>
|
|
156
242
|
</FormShell>
|
|
157
243
|
);
|
|
@@ -166,6 +252,8 @@ export interface RegisterFormProps extends AuthFormBaseProps {
|
|
|
166
252
|
readonly minPasswordLength: number;
|
|
167
253
|
/** The consent statement; may contain links to the terms. Defaults to `messages.fields.consent`. */
|
|
168
254
|
readonly consentLabel?: ReactNode;
|
|
255
|
+
/** The consent box's id and look (`classNames` for its `CheckboxSlot`s). */
|
|
256
|
+
readonly consentProps?: ConsentProps;
|
|
169
257
|
/**
|
|
170
258
|
* The app's own inputs, before the consent checkbox. Their values reach `onRegistered` as
|
|
171
259
|
* `event.fields` when their names are declared in `auth({ registrationFields })`.
|
|
@@ -173,22 +261,12 @@ export interface RegisterFormProps extends AuthFormBaseProps {
|
|
|
173
261
|
readonly extraFields?: ReactNode;
|
|
174
262
|
}
|
|
175
263
|
|
|
176
|
-
export function RegisterForm({
|
|
177
|
-
action,
|
|
178
|
-
|
|
179
|
-
locale,
|
|
180
|
-
next,
|
|
181
|
-
loginHref,
|
|
182
|
-
requireConsent,
|
|
183
|
-
minPasswordLength,
|
|
184
|
-
consentLabel,
|
|
185
|
-
extraFields,
|
|
186
|
-
classNames,
|
|
187
|
-
unstyled,
|
|
188
|
-
submitVariant,
|
|
189
|
-
}: RegisterFormProps) {
|
|
264
|
+
export function RegisterForm(props: RegisterFormProps) {
|
|
265
|
+
const { action, messages, next, loginHref, requireConsent, minPasswordLength, consentLabel, consentProps, extraFields } = props;
|
|
266
|
+
const { classNames, unstyled, submitVariant } = props;
|
|
190
267
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
191
|
-
const errors = useErrors(state, messages);
|
|
268
|
+
const errors = useErrors(state, messages, requireConsent ? ["email", "password", "consent"] : ["email", "password"]);
|
|
269
|
+
const field = getFieldLook(props);
|
|
192
270
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
193
271
|
const footer =
|
|
194
272
|
loginHref === undefined ? undefined : (
|
|
@@ -220,8 +298,7 @@ export function RegisterForm({
|
|
|
220
298
|
required
|
|
221
299
|
defaultValue={state.email ?? ""}
|
|
222
300
|
error={errors.at("email")}
|
|
223
|
-
|
|
224
|
-
locale={locale}
|
|
301
|
+
{...field}
|
|
225
302
|
/>
|
|
226
303
|
<PasswordField
|
|
227
304
|
name="password"
|
|
@@ -230,12 +307,17 @@ export function RegisterForm({
|
|
|
230
307
|
autoComplete="new-password"
|
|
231
308
|
minLength={minPasswordLength}
|
|
232
309
|
error={errors.at("password")}
|
|
233
|
-
|
|
234
|
-
locale={locale}
|
|
310
|
+
{...field}
|
|
235
311
|
/>
|
|
236
312
|
{extraFields}
|
|
237
313
|
{requireConsent ? (
|
|
238
|
-
<
|
|
314
|
+
<ConsentCheckbox
|
|
315
|
+
label={consentLabel ?? messages.fields.consent}
|
|
316
|
+
requiredMessage={messages.errors.auth.consent_required}
|
|
317
|
+
error={errors.at("consent")}
|
|
318
|
+
consentProps={consentProps}
|
|
319
|
+
unstyled={unstyled}
|
|
320
|
+
/>
|
|
239
321
|
) : null}
|
|
240
322
|
</FormShell>
|
|
241
323
|
);
|
|
@@ -245,9 +327,11 @@ export interface ChangePasswordFormProps extends AuthFormBaseProps {
|
|
|
245
327
|
readonly minPasswordLength: number;
|
|
246
328
|
}
|
|
247
329
|
|
|
248
|
-
export function ChangePasswordForm(
|
|
330
|
+
export function ChangePasswordForm(props: ChangePasswordFormProps) {
|
|
331
|
+
const { action, messages, minPasswordLength, classNames, unstyled, submitVariant } = props;
|
|
249
332
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
250
|
-
const errors = useErrors(state, messages);
|
|
333
|
+
const errors = useErrors(state, messages, ["currentPassword", "newPassword"]);
|
|
334
|
+
const field = getFieldLook(props);
|
|
251
335
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
252
336
|
const notice =
|
|
253
337
|
state.status === "ok" ? (
|
|
@@ -272,8 +356,7 @@ export function ChangePasswordForm({ action, messages, locale, minPasswordLength
|
|
|
272
356
|
label={messages.fields.currentPassword}
|
|
273
357
|
autoComplete="current-password"
|
|
274
358
|
error={errors.at("currentPassword")}
|
|
275
|
-
|
|
276
|
-
locale={locale}
|
|
359
|
+
{...field}
|
|
277
360
|
/>
|
|
278
361
|
<PasswordField
|
|
279
362
|
name="newPassword"
|
|
@@ -282,8 +365,7 @@ export function ChangePasswordForm({ action, messages, locale, minPasswordLength
|
|
|
282
365
|
autoComplete="new-password"
|
|
283
366
|
minLength={minPasswordLength}
|
|
284
367
|
error={errors.at("newPassword")}
|
|
285
|
-
|
|
286
|
-
locale={locale}
|
|
368
|
+
{...field}
|
|
287
369
|
/>
|
|
288
370
|
</FormShell>
|
|
289
371
|
);
|
|
@@ -296,9 +378,11 @@ export interface ForgotPasswordFormProps extends AuthFormBaseProps {
|
|
|
296
378
|
}
|
|
297
379
|
|
|
298
380
|
/** Asks for a reset link. Its confirmation is the same whether or not the email has an account. */
|
|
299
|
-
export function ForgotPasswordForm(
|
|
381
|
+
export function ForgotPasswordForm(props: ForgotPasswordFormProps) {
|
|
382
|
+
const { action, messages, ttlMinutes, loginHref, classNames, unstyled, submitVariant } = props;
|
|
300
383
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
301
|
-
const errors = useErrors(state, messages);
|
|
384
|
+
const errors = useErrors(state, messages, ["email"]);
|
|
385
|
+
const field = getFieldLook(props);
|
|
302
386
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
303
387
|
const backToLogin =
|
|
304
388
|
loginHref === undefined ? undefined : (
|
|
@@ -338,8 +422,7 @@ export function ForgotPasswordForm({ action, messages, locale, ttlMinutes, login
|
|
|
338
422
|
required
|
|
339
423
|
defaultValue={state.email ?? ""}
|
|
340
424
|
error={errors.at("email")}
|
|
341
|
-
|
|
342
|
-
locale={locale}
|
|
425
|
+
{...field}
|
|
343
426
|
/>
|
|
344
427
|
</FormShell>
|
|
345
428
|
);
|
|
@@ -352,9 +435,11 @@ export interface ResetPasswordFormProps extends AuthFormBaseProps {
|
|
|
352
435
|
}
|
|
353
436
|
|
|
354
437
|
/** Sets a new password from a reset link; its action goes to the login page on success. */
|
|
355
|
-
export function ResetPasswordForm(
|
|
438
|
+
export function ResetPasswordForm(props: ResetPasswordFormProps) {
|
|
439
|
+
const { action, messages, token, minPasswordLength, classNames, unstyled, submitVariant } = props;
|
|
356
440
|
const [state, formAction, isPending] = useActionState(action, INITIAL_AUTH_FORM_STATE);
|
|
357
|
-
const errors = useErrors(state, messages);
|
|
441
|
+
const errors = useErrors(state, messages, ["newPassword"]);
|
|
442
|
+
const field = getFieldLook(props);
|
|
358
443
|
const slot = createSlotClassGetter({ defaults: DEFAULT_CLASSES, classNames, unstyled });
|
|
359
444
|
return (
|
|
360
445
|
<FormShell
|
|
@@ -375,8 +460,7 @@ export function ResetPasswordForm({ action, messages, locale, token, minPassword
|
|
|
375
460
|
autoComplete="new-password"
|
|
376
461
|
minLength={minPasswordLength}
|
|
377
462
|
error={errors.at("newPassword")}
|
|
378
|
-
|
|
379
|
-
locale={locale}
|
|
463
|
+
{...field}
|
|
380
464
|
/>
|
|
381
465
|
</FormShell>
|
|
382
466
|
);
|