@softure-ai/auth 0.2.0 → 0.2.2

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 CHANGED
@@ -4,6 +4,25 @@ 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.2
8
+
9
+ - Password reset mails can leave from a background job with retry (#494): `auth({ passwordReset: { send, enqueue:
10
+ enqueuePasswordReset } })` from the new entry `@softure-ai/auth/jobs`, with `@softure-ai/jobs` as an optional peer
11
+ dependency (`^0.1.1`). The request then only enqueues `{ userId }` on the `auth.password-reset` queue; the handler
12
+ issues the link when it runs (valid for `ttlMinutes` from the send) and calls the sender, retrying a failure with the
13
+ queue's backoff. `deliverPasswordReset` returns `"queued"` in that mode; `sendPasswordReset(ctx, userId)` is the
14
+ handler's work for an app's own worker. Without `enqueue` nothing changes. Migrate (optional): install
15
+ `@softure-ai/jobs`, add `jobs({ queues: { "auth.password-reset": {} } })` to `softure.config.ts`, pass
16
+ `enqueue: enqueuePasswordReset`, and spread `passwordResetJobHandlers` into the worker's `handlers`.
17
+
18
+ ## 0.2.1
19
+
20
+ - `@softure-ai/auth/jobs` (#491): `authJobHandlers` and `authJobSchedules` run `pruneSessions` (hourly) and
21
+ `prunePasswordResets` (daily) as `@softure-ai/jobs` schedules; `@softure-ai/jobs` (^0.1.1) is a new optional peer. Migrate
22
+ (optional): an app with `@softure-ai/jobs` adds `...authJobSchedules` to `jobs({ schedules })` and
23
+ `...authJobHandlers` to its worker's handlers, then removes the cron or script that called the two prunes. Without
24
+ jobs nothing changes.
25
+
7
26
  ## 0.2.0
8
27
 
9
28
  - **Breaking (#446):** the built-in `pl` dictionary is gone; English is the only built-in copy and the fallback for
package/README.md CHANGED
@@ -15,7 +15,8 @@ for server code, roles (`requireRole`, `authorizeRole`, `hasRole`, and `grant-ro
15
15
  script), `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
- (`mailingResetSender()`). `@softure-ai/auth/testing` creates accounts directly in the database for
18
+ (`mailingResetSender()`); `@softure-ai/auth/jobs` sends them from a background job of `@softure-ai/jobs` with
19
+ retry (`enqueuePasswordReset`, `passwordResetJobHandlers`). `@softure-ai/auth/testing` creates accounts directly in the database for
19
20
  tests (`createTestAccount`, section 4, "Tests").
20
21
 
21
22
  ## 2. Installation
@@ -91,6 +92,7 @@ export default config;
91
92
  | `onRegistered` | `(event, ctx) => Promise<void>` | none | Called after the account is created, inside the same transaction. |
92
93
  | `rewriteRedirect` | `(path, { config, searchParams? }) => string \| Promise<string>` | none | Rewrites the path of every auth redirect: the actions' (login, sign-up, password reset, logout), the login and register pages' redirect of a signed-in visitor and `requireUser`'s redirect to login, e.g. `tagRedirect` from `@softure-ai/analytics/next`, which keeps the channel tag. A page passes its own `searchParams` (`URLSearchParams`; `requireUser` hands over the ones the page gives it); an action passes none, and during a page's render the `Referer` is the page before, not the page itself. A result that is not a path on this app, or an error, leaves auth's own path. |
93
94
  | `passwordReset.send` | `(link, user, details) => Promise<void>` | none | Delivers reset links (section 4, "Password reset"). Without it password reset is off. |
95
+ | `passwordReset.enqueue` | `(ctx, userId) => Promise<void>` | none | Sends the link from a background job instead of the request: `enqueuePasswordReset` of `@softure-ai/auth/jobs` (section 4, "Password reset through jobs"). Needs `send`. |
94
96
  | `passwordReset.ttlMinutes` | `number` (5-1440) | `60` | How long a reset link works. |
95
97
  | `routes` | `{ login, register, changePassword, forgotPassword, resetPassword, afterLogin, afterLogout }` | `/login`, `/register`, `/account/password`, `/forgot-password`, `/reset-password`, `/`, `/login` | Where the pages are mounted and where users land. |
96
98
  | `messages` | partial dictionaries per locale (`en` built in; any other is the app's own translation) | built in | Copy overrides (section 9). |
@@ -441,9 +443,41 @@ auth({
441
443
  link's path and query and swaps the origin in its sender, from what it knows about the user.
442
444
  - The reset page's referrer policy is `same-origin`, so the token in its URL never reaches another
443
445
  site. It still lands in your own access logs; it works once and expires.
444
- - `requestPasswordReset`, `deliverPasswordReset`, `resetPassword`, `findPasswordResetUser` and
446
+ - `requestPasswordReset`, `deliverPasswordReset`, `sendPasswordReset`, `resetPassword`, `findPasswordResetUser` and
445
447
  `prunePasswordResets` in `@softure-ai/auth/server` do the same for your own flows.
446
448
 
449
+ **Password reset through jobs.** Without it, the sender runs once after the response: a provider outage loses the mail.
450
+ With `@softure-ai/jobs` (an optional peer dependency), the request only enqueues the account's id and a worker sends
451
+ the link with retry and backoff:
452
+
453
+ ```ts
454
+ // softure.config.ts
455
+ import { auth } from "@softure-ai/auth";
456
+ import { enqueuePasswordReset, PASSWORD_RESET_QUEUE } from "@softure-ai/auth/jobs";
457
+ import { mailingResetSender } from "@softure-ai/auth/mailing";
458
+ import { jobs } from "@softure-ai/jobs";
459
+
460
+ modules: [
461
+ auth({ passwordReset: { send: mailingResetSender(), enqueue: enqueuePasswordReset } }),
462
+ jobs({ queues: { [PASSWORD_RESET_QUEUE]: { maxAttempts: 5 } } }), // "auth.password-reset"
463
+ ];
464
+
465
+ // scripts/worker.ts
466
+ import { passwordResetJobHandlers } from "@softure-ai/auth/jobs";
467
+ await runJobWorkerProcess({ config, handlers: { ...passwordResetJobHandlers, ...appHandlers } });
468
+ ```
469
+
470
+ - The request (still after the response) looks the account up and enqueues `{ userId }` on `auth.password-reset`,
471
+ deduplicated per account while a job is pending. No address and no token is ever in the payload, and no reset row
472
+ is written in the request.
473
+ - The handler (`passwordResetJobHandler`) issues the link when it runs, so the link works for `ttlMinutes` from the
474
+ send, and calls `passwordReset.send`. Only the token's hash is stored, so a retry issues a new link that replaces
475
+ the last one: a retry after a send whose outcome was not recorded (a worker crash) mails a second link, and only
476
+ the newer works. A thrown sender is logged by its label (never the link) and retried as
477
+ `auth.password_reset_send_failed`; an account deleted in the meantime ends the job without a mail.
478
+ - `mailingResetSender()` reads the registered config: the worker imports `softure.config.ts`, which registers it
479
+ (section 3).
480
+
447
481
  **Your own forms.** `@softure-ai/auth/ui` exports `LoginForm`, `RegisterForm`,
448
482
  `ChangePasswordForm`, `ForgotPasswordForm` and `ResetPasswordForm`; pass them the actions from
449
483
  `@softure-ai/auth/next`. `RegisterForm` takes `consentLabel` and `extraFields` like
@@ -507,6 +541,18 @@ your own 1:1 table, never in `auth.users`. Expired sessions of a user are delete
507
541
  login; `pruneSessions(ctx)` from `@softure-ai/auth/server` deletes all of them for a scheduled job,
508
542
  and `prunePasswordResets(ctx)` does the same for expired reset links.
509
543
 
544
+ **With `@softure-ai/jobs`.** `@softure-ai/auth/jobs` ships the handler and the schedule, so the worker runs the
545
+ cleanup instead of an app cron (`auth.prune-sessions` hourly, `auth.prune-password-resets` daily; jobs README, "Schedules"):
546
+
547
+ ```ts
548
+ // softure.config.ts
549
+ jobs({ schedules: { ...authJobSchedules } }),
550
+ // src/jobs/handlers.ts (the worker's handlers)
551
+ export const handlers: JobHandlers = { ...authJobHandlers /* , the app's own */ };
552
+ ```
553
+
554
+ `@softure-ai/jobs` is an optional peer: an app without it keeps calling the function from its own cron.
555
+
510
556
  **Adopting existing sessions.** An app that moves to this module from its own auth can keep its
511
557
  users, its password hashes when they are `scrypt$N$r$p$salt$key` strings, and its sessions when it
512
558
  stored them as the sha256 hex of the token. Its cookie has another name and its tokens another
@@ -584,7 +630,10 @@ failure. `@softure-ai/privacy` stores the consent through it.
584
630
 
585
631
  `passwordReset.send(link, user, details)`: after a reset request is answered, for an existing
586
632
  account only (section 4, "Password reset"). `mailingResetSender()` from `@softure-ai/auth/mailing`
587
- plugs `@softure-ai/mailing` in here.
633
+ plugs `@softure-ai/mailing` in here. With `passwordReset.enqueue`, it runs in the worker's reset job instead.
634
+
635
+ `passwordReset.enqueue(ctx, userId)`: where a reset request is answered, for an existing account, instead of the
636
+ sender. `enqueuePasswordReset` from `@softure-ai/auth/jobs` plugs `@softure-ai/jobs` in here.
588
637
 
589
638
  ## 11. GDPR
590
639
 
package/dist/index.d.ts CHANGED
@@ -184,6 +184,7 @@ export declare const auth: import("@softure-ai/core").ModuleFactory<{
184
184
  adminEmails: import("zod").ZodDefault<import("zod").ZodUnion<readonly [import("zod").ZodArray<import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodEmail>>, import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodTransform<string[], string>>]>>;
185
185
  passwordReset: import("zod").ZodPrefault<import("zod").ZodObject<{
186
186
  send: import("zod").ZodOptional<import("zod").ZodCustom<import("./password-reset-sender.js").PasswordResetSender, import("./password-reset-sender.js").PasswordResetSender>>;
187
+ enqueue: import("zod").ZodOptional<import("zod").ZodCustom<import("./password-reset-sender.js").PasswordResetEnqueuer, import("./password-reset-sender.js").PasswordResetEnqueuer>>;
187
188
  ttlMinutes: import("zod").ZodDefault<import("zod").ZodNumber>;
188
189
  }, import("zod/v4/core").$strict>>;
189
190
  onRegistered: import("zod").ZodOptional<import("zod").ZodCustom<import("./options.js").OnRegisteredHook, import("./options.js").OnRegisteredHook>>;
@@ -193,7 +194,7 @@ export { INITIAL_AUTH_FORM_STATE } from "./contract.js";
193
194
  export type { AuthErrorCode, AuthFormErrorCode, AuthFormField, AuthFormState, AuthUser, NewSession, RegisteredEvent, SignedIn, } from "./contract.js";
194
195
  export { authMessages, getAuthErrorMessage, type AuthMessages } from "./messages/index.js";
195
196
  export type { AuthOptions, AuthOptionsInput, OnRegisteredHook, RewriteRedirect, RewriteRedirectContext, ScryptParams } from "./options.js";
196
- export { consolePasswordResetSender, type PasswordResetDetails, type PasswordResetSender } from "./password-reset-sender.js";
197
+ export { consolePasswordResetSender, type PasswordResetDetails, type PasswordResetEnqueuer, type PasswordResetSender, } from "./password-reset-sender.js";
197
198
  export { getSessionCookie, type SessionCookie } from "./session-cookie.js";
198
199
  export { toSafeNextPath } from "./safe-next-path.js";
199
200
  export { ADMIN_ROLE, ROLE_NAME_PATTERN } from "./roles.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,SAAS,SAAS,CAAC;AAEhC,2DAA2D;AAC3D,eAAO,MAAM,0BAA0B,6BAA6B,CAAC;AAErE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,4CAA4C,CAAC;AAEjF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQ+B,CAAC;AAEpE;;;GAGG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAwCf,CAAC;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,QAAQ,EACR,UAAU,EACV,eAAe,EACf,QAAQ,GACT,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC3F,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC3I,OAAO,EAAE,0BAA0B,EAAE,KAAK,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAC7H,OAAO,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAA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C3E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Public API of @softure-ai/auth: the module factory for softure.config.ts, its types, messages and
2
2
  // tables, and the development reset sender. Database work is in `@softure-ai/auth/server`, the Next.js adapter in `/next`, the route
3
- // guard in `/proxy`, the forms in `/ui` and the role scripts in `/scripts`.
3
+ // guard in `/proxy`, the reset job in `/jobs`, the forms in `/ui` and the role scripts in `/scripts`.
4
4
  import { defineModule, resolveMigrationsDir } from "@softure-ai/core";
5
5
  import { authMessages } from "./messages/index.js";
6
6
  import { authOptionsSchema } from "./options.js";
@@ -36,8 +36,8 @@ export const AUTH_RATE_LIMIT_BUCKETS = {
36
36
  export const auth = defineModule({
37
37
  manifest: {
38
38
  id: MODULE_ID,
39
- version: "0.2.0",
40
- dependsOn: { security: "^0.2.0", mailing: "^0.2.0?", ops: "^0.2.0?" },
39
+ version: "0.2.2",
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"],
43
43
  env: [
@@ -76,7 +76,7 @@ export const auth = defineModule({
76
76
  });
77
77
  export { INITIAL_AUTH_FORM_STATE } from "./contract.js";
78
78
  export { authMessages, getAuthErrorMessage } from "./messages/index.js";
79
- export { consolePasswordResetSender } from "./password-reset-sender.js";
79
+ export { consolePasswordResetSender, } from "./password-reset-sender.js";
80
80
  export { getSessionCookie } from "./session-cookie.js";
81
81
  export { toSafeNextPath } from "./safe-next-path.js";
82
82
  export { ADMIN_ROLE, ROLE_NAME_PATTERN } from "./roles.js";
package/dist/index.js.map CHANGED
@@ -1 +1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AiB;IAC1B,UAAU,EAAE,EAAE,GAAG,EAAE,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE;IAC5E,OAAO,EAAE,sBAAsB;IAC/B,MAAM,EAAE,eAAe;CACxB,CAAC,CAAC;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAWxD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAqB,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EACL,0BAA0B,GAI3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAsB,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,18 @@
1
+ /** Handlers for the worker: `handlers: { ...authJobHandlers }`. */
2
+ export declare const authJobHandlers: {
3
+ /** Deletes expired sessions (`pruneSessions`). */
4
+ "auth.prune-sessions": import("@softure-ai/jobs").JobHandler<Record<string, never>>;
5
+ /** Deletes expired password reset links (`prunePasswordResets`). */
6
+ "auth.prune-password-resets": import("@softure-ai/jobs").JobHandler<Record<string, never>>;
7
+ };
8
+ /** Schedules for `jobs({ schedules: { ...authJobSchedules } })`: sessions hourly, reset links daily. */
9
+ export declare const authJobSchedules: {
10
+ "auth.prune-sessions": {
11
+ every: string;
12
+ };
13
+ "auth.prune-password-resets": {
14
+ every: string;
15
+ };
16
+ };
17
+ export { enqueuePasswordReset, PASSWORD_RESET_QUEUE, passwordResetJobHandler, passwordResetJobHandlers } from "./password-reset-job.js";
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAQA,mEAAmE;AACnE,eAAO,MAAM,eAAe;IAC1B,kDAAkD;;IAQlD,oEAAoE;;CAQ/C,CAAC;AAExB,wGAAwG;AACxG,eAAO,MAAM,gBAAgB;;;;;;;CAGA,CAAC;AAE9B,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,33 @@
1
+ // The jobs adapter of @softure-ai/auth: its prune functions as `@softure-ai/jobs` handlers and schedules, and the
2
+ // password reset mail sent by a job with retry (an optional peer dependency; only apps that import this entry need it).
3
+ import { ok } from "@softure-ai/core";
4
+ import { defineJobHandler } from "@softure-ai/jobs";
5
+ import { z } from "zod";
6
+ import { prunePasswordResets } from "../server/password-reset.js";
7
+ import { pruneSessions } from "../server/sessions.js";
8
+ /** Handlers for the worker: `handlers: { ...authJobHandlers }`. */
9
+ export const authJobHandlers = {
10
+ /** Deletes expired sessions (`pruneSessions`). */
11
+ "auth.prune-sessions": defineJobHandler({
12
+ payload: z.object({}),
13
+ run: async (_payload, ctx) => {
14
+ await pruneSessions(ctx);
15
+ return ok();
16
+ },
17
+ }),
18
+ /** Deletes expired password reset links (`prunePasswordResets`). */
19
+ "auth.prune-password-resets": defineJobHandler({
20
+ payload: z.object({}),
21
+ run: async (_payload, ctx) => {
22
+ await prunePasswordResets(ctx);
23
+ return ok();
24
+ },
25
+ }),
26
+ };
27
+ /** Schedules for `jobs({ schedules: { ...authJobSchedules } })`: sessions hourly, reset links daily. */
28
+ export const authJobSchedules = {
29
+ "auth.prune-sessions": { every: "1h" },
30
+ "auth.prune-password-resets": { every: "1d" },
31
+ };
32
+ export { enqueuePasswordReset, PASSWORD_RESET_QUEUE, passwordResetJobHandler, passwordResetJobHandlers } from "./password-reset-job.js";
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names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../password-reset-sender.js";
3
+ /** The queue of the reset job; define it in `jobs({ queues })`. */
4
+ export declare const PASSWORD_RESET_QUEUE = "auth.password-reset";
5
+ /**
6
+ * `auth({ passwordReset: { send, enqueue: enqueuePasswordReset } })`: enqueues `{ userId }` on
7
+ * `auth.password-reset`. While a job of the account is pending, a new request joins it.
8
+ */
9
+ export declare const enqueuePasswordReset: PasswordResetEnqueuer;
10
+ /**
11
+ * Issues the link and calls `passwordReset.send`. A gone account ends the job without a mail; a
12
+ * failing sender is logged by its label (never the link) and retried with the queue's backoff.
13
+ */
14
+ export declare const passwordResetJobHandler: import("@softure-ai/jobs").JobHandler<{
15
+ userId: string;
16
+ }>;
17
+ /** The reset job for the worker, next to the prune handlers: `handlers: { ...authJobHandlers, ...passwordResetJobHandlers }`. */
18
+ export declare const passwordResetJobHandlers: JobHandlers;
19
+ //# sourceMappingURL=password-reset-job.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-reset-job.d.ts","sourceRoot":"","sources":["../../src/jobs/password-reset-job.ts"],"names":[],"mappings":"AAKA,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAIzE,mEAAmE;AACnE,eAAO,MAAM,oBAAoB,wBAAwB,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,qBAElC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB;;EAYlC,CAAC;AAEH,iIAAiI;AACjI,eAAO,MAAM,wBAAwB,EAAE,WAAiE,CAAC"}
@@ -0,0 +1,41 @@
1
+ // The password reset job: the request enqueues the account's id (never the address or a token), and
2
+ // the handler issues a fresh link and calls the app's sender. Only the token's hash is stored, so the
3
+ // link cannot be rebuilt from the database: every attempt issues a new one, which replaces the last.
4
+ // A retry after a send that was not recorded therefore mails a second link, and only the newer works.
5
+ import { err, errorLogLabel, ok } from "@softure-ai/core";
6
+ import { defineJobHandler, failJob } from "@softure-ai/jobs";
7
+ import { enqueueJob } from "@softure-ai/jobs/server";
8
+ import { z } from "zod";
9
+ import { getAuthOptions } from "../server/options.js";
10
+ import { sendPasswordReset } from "../server/password-reset.js";
11
+ /** The queue of the reset job; define it in `jobs({ queues })`. */
12
+ export const PASSWORD_RESET_QUEUE = "auth.password-reset";
13
+ /**
14
+ * `auth({ passwordReset: { send, enqueue: enqueuePasswordReset } })`: enqueues `{ userId }` on
15
+ * `auth.password-reset`. While a job of the account is pending, a new request joins it.
16
+ */
17
+ export const enqueuePasswordReset = async (ctx, userId) => {
18
+ await enqueueJob(ctx, { queue: PASSWORD_RESET_QUEUE, payload: { userId }, dedupKey: userId });
19
+ };
20
+ /**
21
+ * Issues the link and calls `passwordReset.send`. A gone account ends the job without a mail; a
22
+ * failing sender is logged by its label (never the link) and retried with the queue's backoff.
23
+ */
24
+ export const passwordResetJobHandler = defineJobHandler({
25
+ payload: z.object({ userId: z.uuid() }),
26
+ run: async ({ userId }, ctx) => {
27
+ if (getAuthOptions(ctx.config).passwordReset.send === undefined)
28
+ return failJob("auth.password_reset_unavailable");
29
+ try {
30
+ await sendPasswordReset(ctx, userId);
31
+ }
32
+ catch (error) {
33
+ console.error(`@softure-ai/auth: the password reset job failed: ${errorLogLabel(error)}`);
34
+ return err("auth.password_reset_send_failed");
35
+ }
36
+ return ok();
37
+ },
38
+ });
39
+ /** The reset job for the worker, next to the prune handlers: `handlers: { ...authJobHandlers, ...passwordResetJobHandlers }`. */
40
+ export const passwordResetJobHandlers = { [PASSWORD_RESET_QUEUE]: passwordResetJobHandler };
41
+ //# sourceMappingURL=password-reset-job.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-reset-job.js","sourceRoot":"","sources":["../../src/jobs/password-reset-job.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,sGAAsG;AACtG,qGAAqG;AACrG,sGAAsG;AACtG,OAAO,EAAE,GAAG,EAAE,aAAa,EAA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AAC;QAChD,CAAC;QACD,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;CACF,CAAC,CAAC;AAEH,iIAAiI;AACjI,MAAM,CAAC,MAAM,wBAAwB,GAAgB,EAAE,CAAC,oBAAoB,CAAC,EAAE,uBAAuB,EAAE,CAAC"}
package/dist/options.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { ModuleContext, SoftureConfig } from "@softure-ai/core";
2
2
  import type { Queryable } from "@softure-ai/db";
3
3
  import { z } from "zod";
4
4
  import type { RegisteredEvent } from "./contract.js";
5
- import type { PasswordResetSender } from "./password-reset-sender.js";
5
+ import type { PasswordResetEnqueuer, PasswordResetSender } from "./password-reset-sender.js";
6
6
  /**
7
7
  * OWASP's scrypt cost for passwords: N = 2^17, r = 8, p = 1. One hash takes 128 * N * r bytes
8
8
  * (128 MiB) and about 0.4 s of a core; Node runs up to four at once on its libuv pool, so a burst of
@@ -60,6 +60,7 @@ export declare const authOptionsSchema: z.ZodObject<{
60
60
  adminEmails: z.ZodDefault<z.ZodUnion<readonly [z.ZodArray<z.ZodPipe<z.ZodString, z.ZodEmail>>, z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>]>>;
61
61
  passwordReset: z.ZodPrefault<z.ZodObject<{
62
62
  send: z.ZodOptional<z.ZodCustom<PasswordResetSender, PasswordResetSender>>;
63
+ enqueue: z.ZodOptional<z.ZodCustom<PasswordResetEnqueuer, PasswordResetEnqueuer>>;
63
64
  ttlMinutes: z.ZodDefault<z.ZodNumber>;
64
65
  }, z.core.$strict>>;
65
66
  onRegistered: z.ZodOptional<z.ZodCustom<OnRegisteredHook, OnRegisteredHook>>;
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAA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AE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAG7F;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAU,CAAC;AAY3C,4FAA4F;AAC5F,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,aAAa,CAAC,SAAS,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAExG,qDAAqD;AACrD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC;CACzC;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,sBAAsB,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAMtG,QAAA,MAAM,YAAY;;;;kBAahB,CAAC;AAyBH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA8F5B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AACjE,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC7D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC"}
package/dist/options.js CHANGED
@@ -122,6 +122,11 @@ export const authOptionsSchema = z.strictObject({
122
122
  .strictObject({
123
123
  /** Delivers reset links. Without it password reset is off: no link, and its pages are not found. */
124
124
  send: z.custom((value) => typeof value === "function", "must be a function").optional(),
125
+ /**
126
+ * Sends the link from a background job instead of the request (`enqueuePasswordReset` of
127
+ * `@softure-ai/auth/jobs`): the job's handler issues the link and calls `send`, with retry.
128
+ */
129
+ enqueue: z.custom((value) => typeof value === "function", "must be a function").optional(),
125
130
  /** How long a reset link works. */
126
131
  ttlMinutes: z.number().int().min(5).max(1440).default(60),
127
132
  })
@@ -131,6 +136,9 @@ export const authOptionsSchema = z.strictObject({
131
136
  /** Rewrites the path of every auth redirect (e.g. `tagRedirect` from `@softure-ai/analytics/next`). */
132
137
  rewriteRedirect: z.custom((value) => typeof value === "function", "must be a function").optional(),
133
138
  }).superRefine((options, context) => {
139
+ if (options.passwordReset.enqueue !== undefined && options.passwordReset.send === undefined) {
140
+ context.addIssue({ code: "custom", path: ["passwordReset", "enqueue"], message: "needs passwordReset.send, which the job calls" });
141
+ }
134
142
  const legacy = options.legacySession?.cookieName;
135
143
  const base = options.cookie.name;
136
144
  if (legacy !== undefined && [base, `__Host-${base}`, `__Secure-${base}`].includes(legacy)) {
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,CAAC;AAE3C,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAC5C,4EAA4E;AAC5E,MAAM,kBAAkB,GAAG,yBAAyB,CAAC;AACrD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAC9C,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAC5D,0EAA0E;AAC1E,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AACpG,MAAM,MAAM,GAAG,gGAAgG,CAAC;AAuBhH,SAAS,Y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AC,MAAM,CAAkB,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,UAAU,EAAE,oBAAoB,CAAC,CAAC,QAAQ,EAAE;CACpH,CAAC,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;IAClC,IAAI,OAAO,CAAC,aAAa,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5F,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,eAAe,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,+CAA+C,EAAE,CAAC,CAAC;IACrI,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,UAAU,CAAC;IACjD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;IACjC,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,IAAI,EAAE,UAAU,IAAI,EAAE,EAAE,YAAY,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1F,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC,EAAE,OAAO,EAAE,oDAAoD,EAAE,CAAC,CAAC;IAC7I,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -1,4 +1,5 @@
1
- import type { Locale } from "@softure-ai/core";
1
+ import type { Locale, ModuleContext } from "@softure-ai/core";
2
+ import type { Queryable } from "@softure-ai/db";
2
3
  import type { AuthUser } from "./contract.js";
3
4
  export interface PasswordResetDetails {
4
5
  /** When the link stops working. */
@@ -18,4 +19,10 @@ export type PasswordResetSender = (link: string, user: AuthUser, details: Passwo
18
19
  * production, where a reset link in the logs would be a live credential in the logs.
19
20
  */
20
21
  export declare const consolePasswordResetSender: PasswordResetSender;
22
+ /**
23
+ * Hands a reset to a background job instead of sending it in the request: `enqueuePasswordReset` of
24
+ * `@softure-ai/auth/jobs` enqueues `{ userId }` on the `auth.password-reset` queue, whose handler issues
25
+ * the link and calls the sender with retry. `ctx.db` is the request's database.
26
+ */
27
+ export type PasswordResetEnqueuer = (ctx: ModuleContext<Queryable>, userId: string) => Promise<void>;
21
28
  //# sourceMappingURL=password-reset-sender.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"password-reset-sender.d.ts","sourceRoot":"","sources":["../src/password-reset-sender.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,oBAAoB;IACnC,mCAAmC;IACnC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEjH;;;GAGG;AACH,eAAO,MAAM,0BAA0B,EAAE,mBAQxC,CAAC"}
1
+ {"version":3,"file":"password-reset-sender.d.ts","sourceRoot":"","sources":["../src/password-reset-sender.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,oBAAoB;IACnC,mCAAmC;IACnC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEjH;;;GAGG;AACH,eAAO,MAAM,0BAA0B,EAAE,mBAQxC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"password-reset-sender.js","sourceRoot":"","sources":["../src/password-reset-sender.ts"],"names":[],"mappings":"AAoBA;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IACrF,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,+HAA+H,CAAC,CAC3I,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,6CAA6C,IAAI,CAAC,KAAK,iBAAiB,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;IACjI,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;AAC3B,CAAC,CAAC"}
1
+ {"version":3,"file":"password-reset-sender.js","sourceRoot":"","sources":["../src/password-reset-sender.ts"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IACrF,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,+HAA+H,CAAC,CAC3I,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,6CAA6C,IAAI,CAAC,KAAK,iBAAiB,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;IACjI,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;AAC3B,CAAC,CAAC"}
@@ -3,7 +3,7 @@ export { loginUser, type LoginInput, type LoginResult } from "./login.js";
3
3
  export { resolveOnlyAccount, type OnlyAccountError, type OnlyAccountErrorCode, type OnlyAccountResult, type ResolveOnlyAccountOptions, } from "./only-account.js";
4
4
  export { getAuthOptions, getAuthRoutes, type AuthRoutes } from "./options.js";
5
5
  export { hashPassword, isPasswordHash, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword, type PasswordMatch } from "./password.js";
6
- export { deliverPasswordReset, findPasswordResetUser, getPasswordResetLink, isPasswordResetEnabled, issuePasswordReset, prunePasswordResets, requestPasswordReset, resetPassword, RESET_TOKEN_PARAM, type PasswordResetRequestInput, type PasswordResetRequestResult, type ResetPasswordErrorCode, type ResetPasswordInput, type ResetPasswordResult, } from "./password-reset.js";
6
+ export { deliverPasswordReset, findPasswordResetUser, getPasswordResetLink, isPasswordResetEnabled, issuePasswordReset, prunePasswordResets, requestPasswordReset, resetPassword, RESET_TOKEN_PARAM, sendPasswordReset, type PasswordResetRequestInput, type PasswordResetRequestResult, type ResetPasswordErrorCode, type ResetPasswordInput, type ResetPasswordResult, } from "./password-reset.js";
7
7
  export { assertDeclaredRole, findUserRoles, getDeclaredRoles, grantRole, isConfiguredAdmin, isDeclaredRole, revokeRole, type RoleChange, type RoleErrorCode, } from "./roles.js";
8
8
  export { authPrivacyContributor, deleteAuthUserData, exportAuthUserData, type AuthUserData } from "./privacy.js";
9
9
  export { isCurrentPassword } from "./reauthenticate.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AA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AiB,EACjB,cAAc,EACd,UAAU,EACV,KAAK,UAAU,EACf,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9G,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,KAAK,WAAW,EAChB,KAAK,yBAAyB,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,KAAK,wBAAwB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -5,7 +5,7 @@ export { loginUser } from "./login.js";
5
5
  export { resolveOnlyAccount, } from "./only-account.js";
6
6
  export { getAuthOptions, getAuthRoutes } from "./options.js";
7
7
  export { hashPassword, isPasswordHash, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword } from "./password.js";
8
- export { deliverPasswordReset, findPasswordResetUser, getPasswordResetLink, isPasswordResetEnabled, issuePasswordReset, prunePasswordResets, requestPasswordReset, resetPassword, RESET_TOKEN_PARAM, } from "./password-reset.js";
8
+ export { deliverPasswordReset, findPasswordResetUser, getPasswordResetLink, isPasswordResetEnabled, issuePasswordReset, prunePasswordResets, requestPasswordReset, resetPassword, RESET_TOKEN_PARAM, sendPasswordReset, } from "./password-reset.js";
9
9
  export { assertDeclaredRole, findUserRoles, getDeclaredRoles, grantRole, isConfiguredAdmin, isDeclaredRole, revokeRole, } from "./roles.js";
10
10
  export { authPrivacyContributor, deleteAuthUserData, exportAuthUserData } from "./privacy.js";
11
11
  export { isCurrentPassword } from "./reauthenticate.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,qGAAqG;AACrG,OAAO,EAAE,cAAc,EAAqF,MAAM,sBAAsB,CAAC;AACzI,OAAO,EAAE,SAAS,EAAqC,MAAM,YAAY,CAAC;AAC1E,OAAO,EACL,kBAAkB,GAKnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAmB,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAsB,MAAM,eAAe,CAAC;AAClJ,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,GAMlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,UAAU,GAGX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAmE,MAAM,eAAe,CAAC;AAC9G,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,aAAa,EACb,kBAAkB,GAGnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAiC,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,qGAAqG;AACrG,OAAO,EAAE,cAAc,EAAqF,MAAM,sBAAsB,CAAC;AACzI,OAAO,EAAE,SAAS,EAAqC,MAAM,YAAY,CAAC;AAC1E,OAAO,EACL,kBAAkB,GAKnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAmB,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAsB,MAAM,eAAe,CAAC;AAClJ,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,GAMlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,UAAU,GAGX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAmE,MAAM,eAAe,CAAC;AAC9G,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,aAAa,EACb,kBAAkB,GAGnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAiC,MAAM,yBAAyB,CAAC"}
@@ -22,9 +22,17 @@ export type PasswordResetRequestResult = Ok<{
22
22
  export declare function requestPasswordReset(ctx: AuthContext, input: PasswordResetRequestInput): Promise<PasswordResetRequestResult>;
23
23
  /**
24
24
  * Issues a reset link for the account with `email` (replacing a pending one) and hands it to the
25
- * app's sender. `no_account` when no account has that email. Sender and database errors propagate.
25
+ * app's sender, or, with `passwordReset.enqueue`, enqueues the account's id for the reset job
26
+ * (`queued`), which issues and sends the link with retry. `no_account` when no account has that
27
+ * email. Sender, enqueuer and database errors propagate.
26
28
  */
27
- export declare function deliverPasswordReset(ctx: AuthContext, email: string): Promise<"sent" | "no_account">;
29
+ export declare function deliverPasswordReset(ctx: AuthContext, email: string): Promise<"sent" | "queued" | "no_account">;
30
+ /**
31
+ * Issues a reset link for the account with `userId` and hands it to the app's sender: the work of
32
+ * the reset job (`@softure-ai/auth/jobs`). `no_account` when the account is gone. Sender and
33
+ * database errors propagate.
34
+ */
35
+ export declare function sendPasswordReset(ctx: AuthContext, userId: string): Promise<"sent" | "no_account">;
28
36
  /** Stores a new reset token for `userId`, replacing a pending one, and returns the token. */
29
37
  export declare function issuePasswordReset(ctx: AuthContext, userId: string): Promise<{
30
38
  readonly token: string;
@@ -1 +1 @@
1
- {"version":3,"file":"password-reset.d.ts","sourceRoot":"","sources":["../../src/server/password-reset.ts"],"names":[],"mappings":"AAKA,OAAO,EAAW,KAAK,GAAG,EAAE,KAAK,EAAE,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAK/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAMjD,oEAAoE;AACpE,eAAO,MAAM,iBAAiB,UAAU,CAAC;AAEzC,sFAAsF;AACtF,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAErE;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,sDAAsD;IACtD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,MAAM,0BAA0B,GAClC,EAAE,CAAC;IAAE,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1
  // Password reset by token. A request counts its buckets and answers the same for every email;
2
- // `deliverPasswordReset` then issues the token and calls the app's sender (the Next adapter runs it
3
- // after the response, so neither its timing nor its failures reveal an account). A reset link
2
+ // `deliverPasswordReset` then issues the token and calls the app's sender, or enqueues the reset job
3
+ // (the Next adapter runs it after the response, so neither its timing nor its failures reveal an account). A reset link
4
4
  // carries 32 random bytes; only their sha256 is stored, one pending link per account, and the reset
5
5
  // deletes the row in the transaction that sets the new password and ends every session.
6
6
  import { err, ok } from "@softure-ai/core";
@@ -42,23 +42,45 @@ export async function requestPasswordReset(ctx, input) {
42
42
  }
43
43
  /**
44
44
  * Issues a reset link for the account with `email` (replacing a pending one) and hands it to the
45
- * app's sender. `no_account` when no account has that email. Sender and database errors propagate.
45
+ * app's sender, or, with `passwordReset.enqueue`, enqueues the account's id for the reset job
46
+ * (`queued`), which issues and sends the link with retry. `no_account` when no account has that
47
+ * email. Sender, enqueuer and database errors propagate.
46
48
  */
47
49
  export async function deliverPasswordReset(ctx, email) {
48
- const send = getAuthOptions(ctx.config).passwordReset.send;
50
+ const { send, enqueue } = getAuthOptions(ctx.config).passwordReset;
49
51
  if (send === undefined) {
50
52
  throw new Error("@softure-ai/auth: deliverPasswordReset needs auth({ passwordReset: { send } })");
51
53
  }
52
- const [user] = await ctx.db
53
- .select({ id: users.id, email: users.email, createdAt: users.createdAt })
54
- .from(users)
55
- .where(eq(users.email, email))
56
- .limit(1);
54
+ const [user] = await ctx.db.select(USER_COLUMNS).from(users).where(eq(users.email, email)).limit(1);
55
+ if (user === undefined)
56
+ return "no_account";
57
+ if (enqueue !== undefined) {
58
+ await enqueue(ctx, user.id);
59
+ return "queued";
60
+ }
61
+ await issueAndSend(ctx, user, send);
62
+ return "sent";
63
+ }
64
+ /**
65
+ * Issues a reset link for the account with `userId` and hands it to the app's sender: the work of
66
+ * the reset job (`@softure-ai/auth/jobs`). `no_account` when the account is gone. Sender and
67
+ * database errors propagate.
68
+ */
69
+ export async function sendPasswordReset(ctx, userId) {
70
+ const send = getAuthOptions(ctx.config).passwordReset.send;
71
+ if (send === undefined) {
72
+ throw new Error("@softure-ai/auth: sendPasswordReset needs auth({ passwordReset: { send } })");
73
+ }
74
+ const [user] = await ctx.db.select(USER_COLUMNS).from(users).where(eq(users.id, userId)).limit(1);
57
75
  if (user === undefined)
58
76
  return "no_account";
77
+ await issueAndSend(ctx, user, send);
78
+ return "sent";
79
+ }
80
+ const USER_COLUMNS = { id: users.id, email: users.email, createdAt: users.createdAt };
81
+ async function issueAndSend(ctx, user, send) {
59
82
  const { token, expiresAt } = await issuePasswordReset(ctx, user.id);
60
83
  await send(getPasswordResetLink(ctx.config, token), user, { expiresAt, locale: ctx.config.locale });
61
- return "sent";
62
84
  }
63
85
  /** Stores a new reset token for `userId`, replacing a pending one, and returns the token. */
64
86
  export async function issuePasswordReset(ctx, userId) {
@@ -1 +1 @@
1
- {"version":3,"file":"password-reset.js","sourceRoot":"","sources":["../../src/server/password-reset.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,oGAAoG;AACpG,8FAA8F;AAC9F,oGAAoG;AACpG,wFAAwF;AACxF,OAAO,EAAE,GAAG,EAAE,EAAE,EAAyC,MAAM,kBAAkB,CAAC;AAElF,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE/E,2FAA2F;AAC3F,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,mBAAmB,E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AC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1G,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QACtE,OAAO,EAAE,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AAED,uFAAuF;AACvF,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,GAAgB;IACxD,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IACtH,OAAO,OAAO,CAAC,MAAM,CAAC;AACxB,CAAC"}
package/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "auth",
3
- "version": "0.2.0",
4
- "dependsOn": { "security": "^0.2.0", "mailing": "^0.2.0?", "ops": "^0.2.0?" },
3
+ "version": "0.2.2",
4
+ "dependsOn": { "security": "^0.2.0", "mailing": "^0.2.0?", "ops": "^0.2.0?", "jobs": "^0.1.1?" },
5
5
  "dbSchema": "auth",
6
6
  "tables": ["users", "sessions", "user_roles", "password_resets"],
7
7
  "env": [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@softure-ai/auth",
3
- "version": "0.2.0",
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.",
3
+ "version": "0.2.2",
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",
7
7
  "sideEffects": false,
@@ -37,6 +37,11 @@
37
37
  "types": "./dist/server/index.d.ts",
38
38
  "default": "./dist/server/index.js"
39
39
  },
40
+ "./jobs": {
41
+ "@softure-ai/source": "./src/jobs/index.ts",
42
+ "types": "./dist/jobs/index.d.ts",
43
+ "default": "./dist/jobs/index.js"
44
+ },
40
45
  "./next": {
41
46
  "@softure-ai/source": "./src/next/index.ts",
42
47
  "types": "./dist/next/index.d.ts",
@@ -78,6 +83,7 @@
78
83
  "zod": "^4.6.5"
79
84
  },
80
85
  "peerDependencies": {
86
+ "@softure-ai/jobs": "^0.1.1",
81
87
  "@softure-ai/mailing": "^0.2.0",
82
88
  "@softure-ai/ops": "^0.2.0",
83
89
  "@softure-ai/ui": "^0.3.0",
@@ -89,6 +95,9 @@
89
95
  "@softure-ai/ui": "^0.3.0"
90
96
  },
91
97
  "peerDependenciesMeta": {
98
+ "@softure-ai/jobs": {
99
+ "optional": true
100
+ },
92
101
  "@softure-ai/mailing": {
93
102
  "optional": true
94
103
  },
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Public API of @softure-ai/auth: the module factory for softure.config.ts, its types, messages and
2
2
  // tables, and the development reset sender. Database work is in `@softure-ai/auth/server`, the Next.js adapter in `/next`, the route
3
- // guard in `/proxy`, the forms in `/ui` and the role scripts in `/scripts`.
3
+ // guard in `/proxy`, the reset job in `/jobs`, the forms in `/ui` and the role scripts in `/scripts`.
4
4
  import { defineModule, resolveMigrationsDir } from "@softure-ai/core";
5
5
  import type { RateLimitBucketInput } from "@softure-ai/security";
6
6
  import { authMessages } from "./messages/index.js";
@@ -42,8 +42,8 @@ export const AUTH_RATE_LIMIT_BUCKETS = {
42
42
  export const auth = defineModule({
43
43
  manifest: {
44
44
  id: MODULE_ID,
45
- version: "0.2.0",
46
- dependsOn: { security: "^0.2.0", mailing: "^0.2.0?", ops: "^0.2.0?" },
45
+ version: "0.2.2",
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"],
49
49
  env: [
@@ -94,7 +94,12 @@ export type {
94
94
  } from "./contract.js";
95
95
  export { authMessages, getAuthErrorMessage, type AuthMessages } from "./messages/index.js";
96
96
  export type { AuthOptions, AuthOptionsInput, OnRegisteredHook, RewriteRedirect, RewriteRedirectContext, ScryptParams } from "./options.js";
97
- export { consolePasswordResetSender, type PasswordResetDetails, type PasswordResetSender } from "./password-reset-sender.js";
97
+ export {
98
+ consolePasswordResetSender,
99
+ type PasswordResetDetails,
100
+ type PasswordResetEnqueuer,
101
+ type PasswordResetSender,
102
+ } from "./password-reset-sender.js";
98
103
  export { getSessionCookie, type SessionCookie } from "./session-cookie.js";
99
104
  export { toSafeNextPath } from "./safe-next-path.js";
100
105
  export { ADMIN_ROLE, ROLE_NAME_PATTERN } from "./roles.js";
@@ -0,0 +1,35 @@
1
+ // The jobs adapter of @softure-ai/auth: its prune functions as `@softure-ai/jobs` handlers and schedules, and the
2
+ // password reset mail sent by a job with retry (an optional peer dependency; only apps that import this entry need it).
3
+ import { ok } from "@softure-ai/core";
4
+ import { defineJobHandler, type JobHandlers, type JobSchedulesInput } from "@softure-ai/jobs";
5
+ import { z } from "zod";
6
+ import { prunePasswordResets } from "../server/password-reset.js";
7
+ import { pruneSessions } from "../server/sessions.js";
8
+
9
+ /** Handlers for the worker: `handlers: { ...authJobHandlers }`. */
10
+ export const authJobHandlers = {
11
+ /** Deletes expired sessions (`pruneSessions`). */
12
+ "auth.prune-sessions": defineJobHandler({
13
+ payload: z.object({}),
14
+ run: async (_payload, ctx) => {
15
+ await pruneSessions(ctx);
16
+ return ok();
17
+ },
18
+ }),
19
+ /** Deletes expired password reset links (`prunePasswordResets`). */
20
+ "auth.prune-password-resets": defineJobHandler({
21
+ payload: z.object({}),
22
+ run: async (_payload, ctx) => {
23
+ await prunePasswordResets(ctx);
24
+ return ok();
25
+ },
26
+ }),
27
+ } satisfies JobHandlers;
28
+
29
+ /** Schedules for `jobs({ schedules: { ...authJobSchedules } })`: sessions hourly, reset links daily. */
30
+ export const authJobSchedules = {
31
+ "auth.prune-sessions": { every: "1h" },
32
+ "auth.prune-password-resets": { every: "1d" },
33
+ } satisfies JobSchedulesInput;
34
+
35
+ export { enqueuePasswordReset, PASSWORD_RESET_QUEUE, passwordResetJobHandler, passwordResetJobHandlers } from "./password-reset-job.js";
@@ -0,0 +1,43 @@
1
+ // The password reset job: the request enqueues the account's id (never the address or a token), and
2
+ // the handler issues a fresh link and calls the app's sender. Only the token's hash is stored, so the
3
+ // link cannot be rebuilt from the database: every attempt issues a new one, which replaces the last.
4
+ // A retry after a send that was not recorded therefore mails a second link, and only the newer works.
5
+ import { err, errorLogLabel, ok } from "@softure-ai/core";
6
+ import { defineJobHandler, failJob, type JobHandlers } from "@softure-ai/jobs";
7
+ import { enqueueJob } from "@softure-ai/jobs/server";
8
+ import { z } from "zod";
9
+ import type { PasswordResetEnqueuer } from "../password-reset-sender.js";
10
+ import { getAuthOptions } from "../server/options.js";
11
+ import { sendPasswordReset } from "../server/password-reset.js";
12
+
13
+ /** The queue of the reset job; define it in `jobs({ queues })`. */
14
+ export const PASSWORD_RESET_QUEUE = "auth.password-reset";
15
+
16
+ /**
17
+ * `auth({ passwordReset: { send, enqueue: enqueuePasswordReset } })`: enqueues `{ userId }` on
18
+ * `auth.password-reset`. While a job of the account is pending, a new request joins it.
19
+ */
20
+ export const enqueuePasswordReset: PasswordResetEnqueuer = async (ctx, userId) => {
21
+ await enqueueJob(ctx, { queue: PASSWORD_RESET_QUEUE, payload: { userId }, dedupKey: userId });
22
+ };
23
+
24
+ /**
25
+ * Issues the link and calls `passwordReset.send`. A gone account ends the job without a mail; a
26
+ * failing sender is logged by its label (never the link) and retried with the queue's backoff.
27
+ */
28
+ export const passwordResetJobHandler = defineJobHandler({
29
+ payload: z.object({ userId: z.uuid() }),
30
+ run: async ({ userId }, ctx) => {
31
+ if (getAuthOptions(ctx.config).passwordReset.send === undefined) return failJob("auth.password_reset_unavailable");
32
+ try {
33
+ await sendPasswordReset(ctx, userId);
34
+ } catch (error) {
35
+ console.error(`@softure-ai/auth: the password reset job failed: ${errorLogLabel(error)}`);
36
+ return err("auth.password_reset_send_failed");
37
+ }
38
+ return ok();
39
+ },
40
+ });
41
+
42
+ /** The reset job for the worker, next to the prune handlers: `handlers: { ...authJobHandlers, ...passwordResetJobHandlers }`. */
43
+ export const passwordResetJobHandlers: JobHandlers = { [PASSWORD_RESET_QUEUE]: passwordResetJobHandler };
package/src/options.ts CHANGED
@@ -3,7 +3,7 @@ import type { ModuleContext, SoftureConfig } from "@softure-ai/core";
3
3
  import type { Queryable } from "@softure-ai/db";
4
4
  import { z } from "zod";
5
5
  import type { RegisteredEvent } from "./contract.js";
6
- import type { PasswordResetSender } from "./password-reset-sender.js";
6
+ import type { PasswordResetEnqueuer, PasswordResetSender } from "./password-reset-sender.js";
7
7
  import { ROLE_NAME_PATTERN } from "./roles.js";
8
8
 
9
9
  /**
@@ -158,6 +158,11 @@ export const authOptionsSchema = z.strictObject({
158
158
  .strictObject({
159
159
  /** Delivers reset links. Without it password reset is off: no link, and its pages are not found. */
160
160
  send: z.custom<PasswordResetSender>((value) => typeof value === "function", "must be a function").optional(),
161
+ /**
162
+ * Sends the link from a background job instead of the request (`enqueuePasswordReset` of
163
+ * `@softure-ai/auth/jobs`): the job's handler issues the link and calls `send`, with retry.
164
+ */
165
+ enqueue: z.custom<PasswordResetEnqueuer>((value) => typeof value === "function", "must be a function").optional(),
161
166
  /** How long a reset link works. */
162
167
  ttlMinutes: z.number().int().min(5).max(1440).default(60),
163
168
  })
@@ -167,6 +172,9 @@ export const authOptionsSchema = z.strictObject({
167
172
  /** Rewrites the path of every auth redirect (e.g. `tagRedirect` from `@softure-ai/analytics/next`). */
168
173
  rewriteRedirect: z.custom<RewriteRedirect>((value) => typeof value === "function", "must be a function").optional(),
169
174
  }).superRefine((options, context) => {
175
+ if (options.passwordReset.enqueue !== undefined && options.passwordReset.send === undefined) {
176
+ context.addIssue({ code: "custom", path: ["passwordReset", "enqueue"], message: "needs passwordReset.send, which the job calls" });
177
+ }
170
178
  const legacy = options.legacySession?.cookieName;
171
179
  const base = options.cookie.name;
172
180
  if (legacy !== undefined && [base, `__Host-${base}`, `__Secure-${base}`].includes(legacy)) {
@@ -1,6 +1,7 @@
1
1
  // The hook through which auth hands a password reset link to the app, which delivers it (a mail,
2
2
  // e.g. through `mailingResetSender()` of `@softure-ai/auth/mailing`). Auth never sends anything itself.
3
- import type { Locale } from "@softure-ai/core";
3
+ import type { Locale, ModuleContext } from "@softure-ai/core";
4
+ import type { Queryable } from "@softure-ai/db";
4
5
  import type { AuthUser } from "./contract.js";
5
6
 
6
7
  export interface PasswordResetDetails {
@@ -31,3 +32,10 @@ export const consolePasswordResetSender: PasswordResetSender = (link, user, deta
31
32
  console.info(`@softure-ai/auth: password reset link for ${user.email}, valid until ${details.expiresAt.toISOString()}: ${link}`);
32
33
  return Promise.resolve();
33
34
  };
35
+
36
+ /**
37
+ * Hands a reset to a background job instead of sending it in the request: `enqueuePasswordReset` of
38
+ * `@softure-ai/auth/jobs` enqueues `{ userId }` on the `auth.password-reset` queue, whose handler issues
39
+ * the link and calls the sender with retry. `ctx.db` is the request's database.
40
+ */
41
+ export type PasswordResetEnqueuer = (ctx: ModuleContext<Queryable>, userId: string) => Promise<void>;
@@ -21,6 +21,7 @@ export {
21
21
  requestPasswordReset,
22
22
  resetPassword,
23
23
  RESET_TOKEN_PARAM,
24
+ sendPasswordReset,
24
25
  type PasswordResetRequestInput,
25
26
  type PasswordResetRequestResult,
26
27
  type ResetPasswordErrorCode,
@@ -1,6 +1,6 @@
1
1
  // Password reset by token. A request counts its buckets and answers the same for every email;
2
- // `deliverPasswordReset` then issues the token and calls the app's sender (the Next adapter runs it
3
- // after the response, so neither its timing nor its failures reveal an account). A reset link
2
+ // `deliverPasswordReset` then issues the token and calls the app's sender, or enqueues the reset job
3
+ // (the Next adapter runs it after the response, so neither its timing nor its failures reveal an account). A reset link
4
4
  // carries 32 random bytes; only their sha256 is stored, one pending link per account, and the reset
5
5
  // deletes the row in the transaction that sets the new password and ends every session.
6
6
  import { err, ok, type Err, type Ok, type SoftureConfig } from "@softure-ai/core";
@@ -8,6 +8,7 @@ import type { RateLimitRejection } from "@softure-ai/security";
8
8
  import { consumeRateLimit } from "@softure-ai/security/server";
9
9
  import { and, eq, gt, lte } from "drizzle-orm";
10
10
  import type { AuthUser } from "../contract.js";
11
+ import type { PasswordResetSender } from "../password-reset-sender.js";
11
12
  import { passwordResets, sessions, users } from "../schema.js";
12
13
  import { getAuthOptions, getAuthRoutes } from "./options.js";
13
14
  import { hashPassword } from "./password.js";
@@ -57,23 +58,46 @@ export async function requestPasswordReset(ctx: AuthContext, input: PasswordRese
57
58
 
58
59
  /**
59
60
  * Issues a reset link for the account with `email` (replacing a pending one) and hands it to the
60
- * app's sender. `no_account` when no account has that email. Sender and database errors propagate.
61
+ * app's sender, or, with `passwordReset.enqueue`, enqueues the account's id for the reset job
62
+ * (`queued`), which issues and sends the link with retry. `no_account` when no account has that
63
+ * email. Sender, enqueuer and database errors propagate.
61
64
  */
62
- export async function deliverPasswordReset(ctx: AuthContext, email: string): Promise<"sent" | "no_account"> {
63
- const send = getAuthOptions(ctx.config).passwordReset.send;
65
+ export async function deliverPasswordReset(ctx: AuthContext, email: string): Promise<"sent" | "queued" | "no_account"> {
66
+ const { send, enqueue } = getAuthOptions(ctx.config).passwordReset;
64
67
  if (send === undefined) {
65
68
  throw new Error("@softure-ai/auth: deliverPasswordReset needs auth({ passwordReset: { send } })");
66
69
  }
67
- const [user] = await ctx.db
68
- .select({ id: users.id, email: users.email, createdAt: users.createdAt })
69
- .from(users)
70
- .where(eq(users.email, email))
71
- .limit(1);
70
+ const [user] = await ctx.db.select(USER_COLUMNS).from(users).where(eq(users.email, email)).limit(1);
72
71
  if (user === undefined) return "no_account";
72
+ if (enqueue !== undefined) {
73
+ await enqueue(ctx, user.id);
74
+ return "queued";
75
+ }
76
+ await issueAndSend(ctx, user, send);
77
+ return "sent";
78
+ }
73
79
 
80
+ /**
81
+ * Issues a reset link for the account with `userId` and hands it to the app's sender: the work of
82
+ * the reset job (`@softure-ai/auth/jobs`). `no_account` when the account is gone. Sender and
83
+ * database errors propagate.
84
+ */
85
+ export async function sendPasswordReset(ctx: AuthContext, userId: string): Promise<"sent" | "no_account"> {
86
+ const send = getAuthOptions(ctx.config).passwordReset.send;
87
+ if (send === undefined) {
88
+ throw new Error("@softure-ai/auth: sendPasswordReset needs auth({ passwordReset: { send } })");
89
+ }
90
+ const [user] = await ctx.db.select(USER_COLUMNS).from(users).where(eq(users.id, userId)).limit(1);
91
+ if (user === undefined) return "no_account";
92
+ await issueAndSend(ctx, user, send);
93
+ return "sent";
94
+ }
95
+
96
+ const USER_COLUMNS = { id: users.id, email: users.email, createdAt: users.createdAt };
97
+
98
+ async function issueAndSend(ctx: AuthContext, user: AuthUser, send: PasswordResetSender): Promise<void> {
74
99
  const { token, expiresAt } = await issuePasswordReset(ctx, user.id);
75
100
  await send(getPasswordResetLink(ctx.config, token), user, { expiresAt, locale: ctx.config.locale });
76
- return "sent";
77
101
  }
78
102
 
79
103
  /** Stores a new reset token for `userId`, replacing a pending one, and returns the token. */