@softure-ai/auth 0.0.0-stage → 0.1.7

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.
Files changed (255) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +490 -2
  4. package/dist/contract.d.ts +46 -0
  5. package/dist/contract.d.ts.map +1 -0
  6. package/dist/contract.js +2 -0
  7. package/dist/contract.js.map +1 -0
  8. package/dist/index.d.ts +194 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +84 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/mailing/index.d.ts +2 -0
  13. package/dist/mailing/index.d.ts.map +1 -0
  14. package/dist/mailing/index.js +4 -0
  15. package/dist/mailing/index.js.map +1 -0
  16. package/dist/mailing/reset-mail.d.ts +27 -0
  17. package/dist/mailing/reset-mail.d.ts.map +1 -0
  18. package/dist/mailing/reset-mail.js +55 -0
  19. package/dist/mailing/reset-mail.js.map +1 -0
  20. package/dist/messages/en.d.ts +98 -0
  21. package/dist/messages/en.d.ts.map +1 -0
  22. package/dist/messages/en.js +93 -0
  23. package/dist/messages/en.js.map +1 -0
  24. package/dist/messages/index.d.ts +201 -0
  25. package/dist/messages/index.d.ts.map +1 -0
  26. package/dist/messages/index.js +11 -0
  27. package/dist/messages/index.js.map +1 -0
  28. package/dist/messages/pl.d.ts +3 -0
  29. package/dist/messages/pl.d.ts.map +1 -0
  30. package/dist/messages/pl.js +92 -0
  31. package/dist/messages/pl.js.map +1 -0
  32. package/dist/next/actions.d.ts +19 -0
  33. package/dist/next/actions.d.ts.map +1 -0
  34. package/dist/next/actions.js +231 -0
  35. package/dist/next/actions.js.map +1 -0
  36. package/dist/next/context.d.ts +4 -0
  37. package/dist/next/context.d.ts.map +1 -0
  38. package/dist/next/context.js +13 -0
  39. package/dist/next/context.js.map +1 -0
  40. package/dist/next/current-user.d.ts +34 -0
  41. package/dist/next/current-user.d.ts.map +1 -0
  42. package/dist/next/current-user.js +77 -0
  43. package/dist/next/current-user.js.map +1 -0
  44. package/dist/next/index.d.ts +8 -0
  45. package/dist/next/index.d.ts.map +1 -0
  46. package/dist/next/index.js +9 -0
  47. package/dist/next/index.js.map +1 -0
  48. package/dist/next/logout-button.d.ts +7 -0
  49. package/dist/next/logout-button.d.ts.map +1 -0
  50. package/dist/next/logout-button.js +12 -0
  51. package/dist/next/logout-button.js.map +1 -0
  52. package/dist/next/messages.d.ts +5 -0
  53. package/dist/next/messages.d.ts.map +1 -0
  54. package/dist/next/messages.js +7 -0
  55. package/dist/next/messages.js.map +1 -0
  56. package/dist/next/pages.d.ts +31 -0
  57. package/dist/next/pages.d.ts.map +1 -0
  58. package/dist/next/pages.js +118 -0
  59. package/dist/next/pages.js.map +1 -0
  60. package/dist/next/params.d.ts +3 -0
  61. package/dist/next/params.d.ts.map +1 -0
  62. package/dist/next/params.js +4 -0
  63. package/dist/next/params.js.map +1 -0
  64. package/dist/next/route.d.ts +3 -0
  65. package/dist/next/route.d.ts.map +1 -0
  66. package/dist/next/route.js +17 -0
  67. package/dist/next/route.js.map +1 -0
  68. package/dist/next/search-params.d.ts +5 -0
  69. package/dist/next/search-params.d.ts.map +1 -0
  70. package/dist/next/search-params.js +13 -0
  71. package/dist/next/search-params.js.map +1 -0
  72. package/dist/next/session-cookie.d.ts +11 -0
  73. package/dist/next/session-cookie.d.ts.map +1 -0
  74. package/dist/next/session-cookie.js +71 -0
  75. package/dist/next/session-cookie.js.map +1 -0
  76. package/dist/options.d.ts +72 -0
  77. package/dist/options.d.ts.map +1 -0
  78. package/dist/options.js +115 -0
  79. package/dist/options.js.map +1 -0
  80. package/dist/password-reset-sender.d.ts +21 -0
  81. package/dist/password-reset-sender.d.ts.map +1 -0
  82. package/dist/password-reset-sender.js +12 -0
  83. package/dist/password-reset-sender.js.map +1 -0
  84. package/dist/proxy/index.d.ts +14 -0
  85. package/dist/proxy/index.d.ts.map +1 -0
  86. package/dist/proxy/index.js +59 -0
  87. package/dist/proxy/index.js.map +1 -0
  88. package/dist/redirect-target.d.ts +7 -0
  89. package/dist/redirect-target.d.ts.map +1 -0
  90. package/dist/redirect-target.js +25 -0
  91. package/dist/redirect-target.js.map +1 -0
  92. package/dist/roles.d.ts +5 -0
  93. package/dist/roles.d.ts.map +1 -0
  94. package/dist/roles.js +6 -0
  95. package/dist/roles.js.map +1 -0
  96. package/dist/safe-next-path.d.ts +5 -0
  97. package/dist/safe-next-path.d.ts.map +1 -0
  98. package/dist/safe-next-path.js +25 -0
  99. package/dist/safe-next-path.js.map +1 -0
  100. package/dist/schema.d.ts +302 -0
  101. package/dist/schema.d.ts.map +1 -0
  102. package/dist/schema.js +37 -0
  103. package/dist/schema.js.map +1 -0
  104. package/dist/scripts/index.d.ts +3 -0
  105. package/dist/scripts/index.d.ts.map +1 -0
  106. package/dist/scripts/index.js +5 -0
  107. package/dist/scripts/index.js.map +1 -0
  108. package/dist/scripts/role-scripts.d.ts +15 -0
  109. package/dist/scripts/role-scripts.d.ts.map +1 -0
  110. package/dist/scripts/role-scripts.js +76 -0
  111. package/dist/scripts/role-scripts.js.map +1 -0
  112. package/dist/scripts/temporary-password.d.ts +12 -0
  113. package/dist/scripts/temporary-password.d.ts.map +1 -0
  114. package/dist/scripts/temporary-password.js +47 -0
  115. package/dist/scripts/temporary-password.js.map +1 -0
  116. package/dist/server/change-password.d.ts +14 -0
  117. package/dist/server/change-password.d.ts.map +1 -0
  118. package/dist/server/change-password.js +50 -0
  119. package/dist/server/change-password.js.map +1 -0
  120. package/dist/server/health.d.ts +3 -0
  121. package/dist/server/health.d.ts.map +1 -0
  122. package/dist/server/health.js +15 -0
  123. package/dist/server/health.js.map +1 -0
  124. package/dist/server/index.d.ts +12 -0
  125. package/dist/server/index.d.ts.map +1 -0
  126. package/dist/server/index.js +14 -0
  127. package/dist/server/index.js.map +1 -0
  128. package/dist/server/login.d.ts +14 -0
  129. package/dist/server/login.d.ts.map +1 -0
  130. package/dist/server/login.js +50 -0
  131. package/dist/server/login.js.map +1 -0
  132. package/dist/server/options.d.ts +19 -0
  133. package/dist/server/options.d.ts.map +1 -0
  134. package/dist/server/options.js +50 -0
  135. package/dist/server/options.js.map +1 -0
  136. package/dist/server/password-reset.d.ts +54 -0
  137. package/dist/server/password-reset.d.ts.map +1 -0
  138. package/dist/server/password-reset.js +134 -0
  139. package/dist/server/password-reset.js.map +1 -0
  140. package/dist/server/password.d.ts +25 -0
  141. package/dist/server/password.d.ts.map +1 -0
  142. package/dist/server/password.js +93 -0
  143. package/dist/server/password.js.map +1 -0
  144. package/dist/server/privacy.d.ts +33 -0
  145. package/dist/server/privacy.d.ts.map +1 -0
  146. package/dist/server/privacy.js +52 -0
  147. package/dist/server/privacy.js.map +1 -0
  148. package/dist/server/rate-limits.d.ts +22 -0
  149. package/dist/server/rate-limits.d.ts.map +1 -0
  150. package/dist/server/rate-limits.js +45 -0
  151. package/dist/server/rate-limits.js.map +1 -0
  152. package/dist/server/reauthenticate.d.ts +7 -0
  153. package/dist/server/reauthenticate.d.ts.map +1 -0
  154. package/dist/server/reauthenticate.js +16 -0
  155. package/dist/server/reauthenticate.js.map +1 -0
  156. package/dist/server/register.d.ts +23 -0
  157. package/dist/server/register.d.ts.map +1 -0
  158. package/dist/server/register.js +64 -0
  159. package/dist/server/register.js.map +1 -0
  160. package/dist/server/roles.d.ts +25 -0
  161. package/dist/server/roles.d.ts.map +1 -0
  162. package/dist/server/roles.js +56 -0
  163. package/dist/server/roles.js.map +1 -0
  164. package/dist/server/session-token.d.ts +12 -0
  165. package/dist/server/session-token.d.ts.map +1 -0
  166. package/dist/server/session-token.js +22 -0
  167. package/dist/server/session-token.js.map +1 -0
  168. package/dist/server/sessions.d.ts +24 -0
  169. package/dist/server/sessions.d.ts.map +1 -0
  170. package/dist/server/sessions.js +50 -0
  171. package/dist/server/sessions.js.map +1 -0
  172. package/dist/server/switches.d.ts +9 -0
  173. package/dist/server/switches.d.ts.map +1 -0
  174. package/dist/server/switches.js +34 -0
  175. package/dist/server/switches.js.map +1 -0
  176. package/dist/server/validation.d.ts +10 -0
  177. package/dist/server/validation.d.ts.map +1 -0
  178. package/dist/server/validation.js +32 -0
  179. package/dist/server/validation.js.map +1 -0
  180. package/dist/session-cookie.d.ts +14 -0
  181. package/dist/session-cookie.d.ts.map +1 -0
  182. package/dist/session-cookie.js +31 -0
  183. package/dist/session-cookie.js.map +1 -0
  184. package/dist/testing/account.d.ts +17 -0
  185. package/dist/testing/account.d.ts.map +1 -0
  186. package/dist/testing/account.js +31 -0
  187. package/dist/testing/account.js.map +1 -0
  188. package/dist/testing/index.d.ts +2 -0
  189. package/dist/testing/index.d.ts.map +1 -0
  190. package/dist/testing/index.js +4 -0
  191. package/dist/testing/index.js.map +1 -0
  192. package/dist/ui/auth-forms.d.ts +64 -0
  193. package/dist/ui/auth-forms.d.ts.map +1 -0
  194. package/dist/ui/auth-forms.js +67 -0
  195. package/dist/ui/auth-forms.js.map +1 -0
  196. package/dist/ui/index.d.ts +2 -0
  197. package/dist/ui/index.d.ts.map +1 -0
  198. package/dist/ui/index.js +4 -0
  199. package/dist/ui/index.js.map +1 -0
  200. package/migrations/0001_create_users_and_sessions.sql +25 -0
  201. package/migrations/0002_create_user_roles.sql +10 -0
  202. package/migrations/0003_create_password_resets.sql +15 -0
  203. package/migrations/0004_index_users_created_at.sql +5 -0
  204. package/module.json +34 -0
  205. package/package.json +97 -4
  206. package/src/contract.ts +67 -0
  207. package/src/index.ts +100 -0
  208. package/src/mailing/index.ts +3 -0
  209. package/src/mailing/reset-mail.ts +73 -0
  210. package/src/messages/en.ts +92 -0
  211. package/src/messages/index.ts +15 -0
  212. package/src/messages/pl.ts +93 -0
  213. package/src/next/actions.ts +240 -0
  214. package/src/next/context.ts +14 -0
  215. package/src/next/current-user.ts +90 -0
  216. package/src/next/index.ts +33 -0
  217. package/src/next/logout-button.tsx +22 -0
  218. package/src/next/messages.ts +9 -0
  219. package/src/next/next-modules.d.ts +16 -0
  220. package/src/next/pages.tsx +223 -0
  221. package/src/next/params.ts +4 -0
  222. package/src/next/route.ts +17 -0
  223. package/src/next/search-params.ts +14 -0
  224. package/src/next/session-cookie.ts +79 -0
  225. package/src/options.ts +154 -0
  226. package/src/password-reset-sender.ts +33 -0
  227. package/src/proxy/index.ts +85 -0
  228. package/src/redirect-target.ts +24 -0
  229. package/src/roles.ts +7 -0
  230. package/src/safe-next-path.ts +21 -0
  231. package/src/schema.ts +45 -0
  232. package/src/scripts/index.ts +8 -0
  233. package/src/scripts/role-scripts.ts +98 -0
  234. package/src/scripts/temporary-password.ts +62 -0
  235. package/src/server/change-password.ts +64 -0
  236. package/src/server/health.ts +16 -0
  237. package/src/server/index.ts +46 -0
  238. package/src/server/login.ts +61 -0
  239. package/src/server/options.ts +64 -0
  240. package/src/server/password-reset.ts +164 -0
  241. package/src/server/password.ts +108 -0
  242. package/src/server/privacy.ts +70 -0
  243. package/src/server/rate-limits.ts +51 -0
  244. package/src/server/reauthenticate.ts +16 -0
  245. package/src/server/register.ts +87 -0
  246. package/src/server/roles.ts +72 -0
  247. package/src/server/session-token.ts +25 -0
  248. package/src/server/sessions.ts +65 -0
  249. package/src/server/switches.ts +31 -0
  250. package/src/server/validation.ts +37 -0
  251. package/src/session-cookie.ts +47 -0
  252. package/src/testing/account.ts +43 -0
  253. package/src/testing/index.ts +3 -0
  254. package/src/ui/auth-forms.tsx +383 -0
  255. package/src/ui/index.ts +16 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ Newest first. Each version lists what changed for an app that uses `@softure-ai/auth`. When an app has run a version in
4
+ production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
5
+ "Definition of done"). Versions before the first one below are described in their GitHub Releases (`auth@x.y.z`).
6
+
7
+ ## 0.1.7
8
+
9
+ - `module.json` names `mailing` and `ops` as optional dependencies.
10
+ - Adapters and commands use the configured database handle; `@softure-ai/ui` is a peer dependency.
11
+ - Deny-by-default route guard and the legacy session cookie name.
12
+ - Registration fields, a register page factory, a submit variant and longer `next` paths.
13
+ - Legacy password hashes normalised to NFC, an unchanged new password refused, conditional reset buckets, session revocation.
14
+ - `set-temporary-password` ops script; `@softure-ai/ops` is an optional peer.
15
+ - `createTestAccount` in `@softure-ai/auth/testing`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SOFTURE
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,491 @@
1
- # Temporary Holding Version
1
+ # @softure-ai/auth
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Accounts for a Next.js app: register with a required consent, login, logout, password change,
4
+ password reset by an emailed link, roles with admin-only surfaces that fail closed, database sessions, a route guard for `proxy.ts`, and ready pages and forms. The reference module
5
+ of the SOFTURE standard (docs/02): it has every layer, from migrations to messages. It counts
6
+ attempts with the rate limiter of `@softure-ai/security`, and its route guard is separate from
7
+ channel tagging.
8
+
9
+ ## 1. What it provides
10
+
11
+ Users and sessions in the `auth` schema, scrypt password hashes, opaque session cookies, register,
12
+ login, logout, password change and password reset as server actions and pages, `getCurrentUser` / `requireUser`
13
+ for server code, roles (`requireRole`, `authorizeRole`, `hasRole`, and `grant-role` /
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
16
+ `GET /api/health` of `@softure-ai/ops` runs (every auth table answers, no rows read).
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
19
+ tests (`createTestAccount`, section 4, "Tests").
20
+
21
+ ## 2. Installation
22
+
23
+ ```bash
24
+ npm install @softure-ai/auth @softure-ai/security @softure-ai/core @softure-ai/db @softure-ai/ui drizzle-orm
25
+ # only for the ops scripts in @softure-ai/auth/scripts (section 4, "Roles" and "Account recovery"):
26
+ npm install @softure-ai/ops
27
+ ```
28
+
29
+ Peer dependencies: `next` 16, `react` 19, `drizzle-orm`; optional: `@softure-ai/mailing` for
30
+ `@softure-ai/auth/mailing`, `@softure-ai/ops` for `@softure-ai/auth/scripts`. No other entry
31
+ imports them.
32
+
33
+ ## 3. Configuration
34
+
35
+ ```ts
36
+ import { defineSoftureConfig } from "@softure-ai/core";
37
+ import { registerSoftureConfig } from "@softure-ai/core/next";
38
+ import { auth, AUTH_RATE_LIMIT_BUCKETS } from "@softure-ai/auth";
39
+ import { cloudflareIp, security } from "@softure-ai/security";
40
+
41
+ const config = defineSoftureConfig({
42
+ database: { url: process.env.DATABASE_URL! },
43
+ locale: "pl",
44
+ timezone: "Europe/Warsaw",
45
+ appOrigin: process.env.APP_ORIGIN!,
46
+ modules: [
47
+ // auth counts attempts in these buckets; change the numbers, keep the names.
48
+ security({ clientIp: cloudflareIp(), buckets: { ...AUTH_RATE_LIMIT_BUCKETS } }),
49
+ auth({
50
+ routes: { afterLogin: "/dashboard" },
51
+ password: { minLength: 12 },
52
+ onRegistered: async ({ user, consent }, ctx) => {
53
+ // Runs in the registration transaction: throw to roll the account back.
54
+ },
55
+ }),
56
+ ],
57
+ });
58
+
59
+ registerSoftureConfig(config);
60
+ export default config;
61
+ ```
62
+
63
+ | Option | Type | Default | Meaning |
64
+ | --- | --- | --- | --- |
65
+ | `password.minLength` | `number` (8-128) | `10` | Shortest new password, in characters. The longest is 1024. |
66
+ | `password.scrypt` | `{ cost, blockSize, parallelization }` | `{ 2 ** 17, 8, 1 }` | scrypt N, r, p (OWASP). Raising them rehashes each password at its owner's next login. Memory: 128 × N × r bytes per hash, so the default takes 128 MiB and about 0.4 s of one core; Node runs up to four hashes at once (its libuv pool, `UV_THREADPOOL_SIZE`), about 512 MiB at a burst of logins. On a small server, lower `cost` to `2 ** 16` (64 MiB) or `2 ** 15` (32 MiB) and leave the pool at four. |
67
+ | `session.ttlDays` | `number` (1-365) | `30` | Session lifetime from login. It is not extended by use. |
68
+ | `cookie.name` | `string` | `"softure_session"` | Base name of the session cookie (see below). |
69
+ | `cookie.domain` | `string` | none (host-only) | Share the session with subdomains, e.g. `example.com` for the apex and `app.example.com`. |
70
+ | `cookie.secure` | `boolean` | `appOrigin` is https | Send the cookie over HTTPS only. |
71
+ | `requireConsent` | `boolean` | `true` | Registration needs the consent checkbox. |
72
+ | `registrationFields` | `string[]` | `[]` | Extra register form fields handed to `onRegistered` as `event.fields` (section 10). Names: `a-z` first, then letters, digits or `_`, at most 32; not `email`, `password`, `next` or `consent`. |
73
+ | `legacySession` | `{ cookieName, tokenPattern }` | none | Sessions of the system the app took over (section 5, "Adopting existing sessions"). |
74
+ | `registrationClosed` | `boolean` | `false` | Declared default of the `auth.registration_closed` switch. |
75
+ | `roles` | `string[]` | `[]` | Role names the app checks besides `admin` (always declared): `a-z`, `0-9`, `_`, `-`, at most 32. |
76
+ | `adminEmails` | `string[]` | `[]` | Initial admin list: while an email is listed, its account holds `admin`. Auth does not verify emails, so create these accounts before you deploy the list (section 4, "Roles"). |
77
+ | `onRegistered` | `(event, ctx) => Promise<void>` | none | Called after the account is created, inside the same transaction. |
78
+ | `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. |
79
+ | `passwordReset.send` | `(link, user, details) => Promise<void>` | none | Delivers reset links (section 4, "Password reset"). Without it password reset is off. |
80
+ | `passwordReset.ttlMinutes` | `number` (5-1440) | `60` | How long a reset link works. |
81
+ | `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. |
82
+ | `messages` | partial `pl` / `en` dictionaries | built in | Copy overrides (section 9). |
83
+
84
+ **Cookie.** Always `HttpOnly`, `SameSite=Lax`, `Path=/`, `Max-Age` = the TTL. A secure cookie gets
85
+ the prefix browsers enforce: `__Host-softure_session` when it is host-only, `__Secure-softure_session`
86
+ with `cookie.domain`. Over plain HTTP (local development) it keeps the bare name.
87
+
88
+ **Rate limits** (`AUTH_RATE_LIMIT_BUCKETS`, configured in `security`): `register` 5 and `login` 50
89
+ per client address, `login-account` 10 per email, `change-password` 10 per user,
90
+ `password-reset` 10 (link requests) and `password-reset-confirm` 10 (new passwords) per client
91
+ address, `password-reset-account` 3 per email (the mails one address can get), each per 15
92
+ minutes. Attempts are counted before any password is hashed. A successful login forgets the
93
+ email's failed attempts, not the address's: the per-address `login` bucket counts every login,
94
+ successful or not, so a test suite that logs in many times from one address must raise `login`
95
+ (or give each test its own address). `login-account` is a lockout by design: ten wrong
96
+ passwords for one email, from any addresses, block logins to that account for the rest of the
97
+ window, the owner's included. Raise its limit if that trade-off is wrong for your app. Auth checks
98
+ at its first call that the buckets it counts in exist and names the missing ones: the three
99
+ `password-reset*` buckets only when `passwordReset.send` is set. A request whose client address
100
+ cannot be resolved is refused (`security.client_unidentified`); the security README shows resolver
101
+ chains for production and for development and test stacks.
102
+
103
+ ## 4. Mounting
104
+
105
+ One line per file, owned by the app (docs/02 §8):
106
+
107
+ ```ts
108
+ // app/login/page.tsx
109
+ export { LoginPage as default } from "@softure-ai/auth/next";
110
+ // app/register/page.tsx
111
+ export { RegisterPage as default } from "@softure-ai/auth/next";
112
+ // app/account/password/page.tsx
113
+ export { ChangePasswordPage as default } from "@softure-ai/auth/next";
114
+ // app/forgot-password/page.tsx and app/reset-password/page.tsx (with passwordReset.send)
115
+ export { ForgotPasswordPage as default } from "@softure-ai/auth/next";
116
+ export { ResetPasswordPage as default } from "@softure-ai/auth/next";
117
+ // app/api/auth/session/route.ts: { user: { id, email } | null }, never cached
118
+ export { getSessionRoute as GET } from "@softure-ai/auth/next";
119
+ ```
120
+
121
+ The register page takes a consent label (links to your terms) and inputs of your own through
122
+ `createRegisterPage`, so you keep the module's page:
123
+
124
+ ```tsx
125
+ // app/register/page.tsx
126
+ import { createRegisterPage } from "@softure-ai/auth/next";
127
+
128
+ export default createRegisterPage({
129
+ consentLabel: (
130
+ <>
131
+ I accept the <a href="/terms">terms</a> and the <a href="/privacy">privacy policy</a>.
132
+ </>
133
+ ),
134
+ extraFields: <input type="hidden" name="plan" value="pro" />,
135
+ });
136
+ ```
137
+
138
+ A field reaches `onRegistered` only when its name is in `auth({ registrationFields })` (section 10).
139
+ The page also carries a declared field from its own URL as a hidden input, so with
140
+ `registrationFields: ["z"]` a visit to `/register?z=newsletter` hands `{ z: "newsletter" }` to the hook.
141
+
142
+ The server actions (`loginAction`, `registerAction`, `changePasswordAction`, `forgotPasswordAction`,
143
+ `resetPasswordAction`, `logoutAction`) need no mounting. In your own pages and layouts:
144
+
145
+ ```tsx
146
+ import { getCurrentUser, LogoutButton, requireUser } from "@softure-ai/auth/next";
147
+
148
+ export default async function AccountPage() {
149
+ const user = await requireUser(); // redirects to the login page without a live session
150
+ return (
151
+ <main>
152
+ <p>{user.email}</p>
153
+ <LogoutButton />
154
+ </main>
155
+ );
156
+ }
157
+ ```
158
+
159
+ `requireUser({ next: "/account" })` brings the user back after login; `getCurrentUser()` returns
160
+ the user or `null`. Both read the session once per request. The redirect to login goes through the
161
+ app's `rewriteRedirect` (options table); a page outside the proxy's guard passes its own search
162
+ params so the login URL can keep its channel tag:
163
+
164
+ ```tsx
165
+ export default async function SettingsPage({ searchParams }: { searchParams: Promise<Record<string, string | string[] | undefined>> }) {
166
+ const user = await requireUser({ next: "/settings", searchParams: await searchParams });
167
+ // …
168
+ }
169
+ ```
170
+
171
+ Private prefixes still belong behind the route guard below; the option covers the pages outside it
172
+ (billing's payment page passes its parameters).
173
+
174
+ **Route guard.** `createAuthGuard` returns `(request) => Response | null`: a redirect to the login
175
+ page (with `?next=`) for a protected path without a session cookie, `null` otherwise. It only
176
+ checks that the cookie is present, so **every private page and action still calls
177
+ `requireUser`**: the guard is a convenience, not the access check. Paths are compared decoded and
178
+ lowercased (`/%61ccount` and `/ACCOUNT` are guarded like `/account`). It imports nothing from Next,
179
+ so it chains with other proxy pieces:
180
+
181
+ ```ts
182
+ // proxy.ts
183
+ import { createAuthGuard } from "@softure-ai/auth/proxy";
184
+ import { NextResponse, type NextRequest } from "next/server";
185
+ import softureConfig from "./softure.config";
186
+
187
+ const guard = createAuthGuard(softureConfig, { protect: ["/account", "/dashboard"] });
188
+
189
+ export function proxy(request: NextRequest) {
190
+ return guard(request) ?? NextResponse.next();
191
+ }
192
+
193
+ // Static files never need the guard.
194
+ export const config = { matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"] };
195
+ ```
196
+
197
+ (Name the imported SOFTURE config differently, e.g. `softureConfig`, when `proxy.ts` also exports
198
+ Next's `config`.)
199
+
200
+ A protected prefix matches whole path segments (`/account` covers `/account/password`, not
201
+ `/accounting`). The change-password route is always protected. Redirects are built on `appOrigin`.
202
+
203
+ An app that is private by default protects `"/"` and lists its public paths in `exclude`, which is
204
+ checked first:
205
+
206
+ ```ts
207
+ const guard = createAuthGuard(softureConfig, { protect: ["/"], exclude: ["/", "/pricing", "/blog", "/api/public"] });
208
+ ```
209
+
210
+ In `exclude`, `"/"` is the home page only; any other entry matches whole segments like `protect`.
211
+ Auth's own public pages (login, register, forgot and reset password) and `/api/auth/session` are
212
+ never guarded, so `protect: ["/"]` cannot send the login page to itself. The change-password route
213
+ stays guarded even under an excluded prefix.
214
+
215
+ **Roles.** A role is a declared name (`admin`, plus `auth({ roles: ["editor"] })`) held by an
216
+ account: as a row in `auth.user_roles`, or, for `admin` only, through `adminEmails`. Nothing is
217
+ granted by default: with no admin listed and no rows, every admin-only surface stays closed.
218
+
219
+ ```tsx
220
+ import { ADMIN_ROLE } from "@softure-ai/auth";
221
+ import { authorizeRole, hasRole, requireRole } from "@softure-ai/auth/next";
222
+
223
+ // app/admin/page.tsx (pages, layouts and route handlers)
224
+ export default async function AdminPage() {
225
+ await requireRole(ADMIN_ROLE); // anyone without the role, signed in or not: Next's "not found"
226
+ return <main>…</main>;
227
+ }
228
+
229
+ // a server action: check first, before reading the form
230
+ export async function publishAction(formData: FormData) {
231
+ const admin = await authorizeRole(ADMIN_ROLE); // Ok<AuthUser> or Err<"auth.forbidden">
232
+ if (!admin.ok) return admin;
233
+ // …
234
+ }
235
+
236
+ // UI only, e.g. whether to show a link; the target page checks again
237
+ const showAdminLink = await hasRole(ADMIN_ROLE);
238
+ ```
239
+
240
+ Roles are read once per request and never cached across requests or stored in the cookie, so a
241
+ revoke takes effect on the next request. Asking for a role the app did not declare throws: a typo
242
+ fails loudly instead of quietly closing (or opening) a surface. Keep admin paths out of the proxy
243
+ guard's `protect` list, or anonymous visitors are sent to the login page instead of "not found".
244
+
245
+ **The first admin.** Either list the email in `adminEmails` (register that account yourself
246
+ before the list is deployed, or keep registration closed meanwhile: whoever registers a listed email
247
+ first becomes admin), or, safer, grant the role with the ops script, which needs database access:
248
+
249
+ ```ts
250
+ // scripts/grant-role.ts (bundled and run like the migrate step, @softure-ai/ops README)
251
+ import { createGrantRoleScript } from "@softure-ai/auth/scripts";
252
+ import { runOpsScript } from "@softure-ai/ops/scripts";
253
+ import config from "../softure.config";
254
+
255
+ process.exitCode = await runOpsScript({ script: createGrantRoleScript(config), argv: process.argv.slice(2), config });
256
+ ```
257
+
258
+ `node grant-role.mjs --email=owner@example.com --role=admin` prints the account's roles before and
259
+ after (by user id, never the email) and rolls back; `--commit` writes. `createRevokeRoleScript`
260
+ is its pair. Both refuse an unknown email, an undeclared role, a role already granted (grant) or
261
+ not stored (revoke); an `admin` that comes from `adminEmails` is removed from the list, not by the
262
+ script. `grantRole`, `revokeRole` and `findUserRoles` in `@softure-ai/auth/server` do the same for
263
+ your own code.
264
+
265
+ **Account recovery.** `revokeUserSessions(ctx, userId, { except? })` from `@softure-ai/auth/server`
266
+ ends every session of an account (all but `except`) and returns how many; each device logs in
267
+ again. For an owner who lost access without a reset mail, the `set-temporary-password` ops script
268
+ sets a random password (at least 20 characters, and at least `password.minLength`), ends every
269
+ session and the pending reset link, and prints the password once:
270
+
271
+ ```ts
272
+ // scripts/set-temporary-password.ts (bundled and run like grant-role)
273
+ import { createSetTemporaryPasswordScript } from "@softure-ai/auth/scripts";
274
+ import { runOpsScript } from "@softure-ai/ops/scripts";
275
+ import config from "../softure.config";
276
+
277
+ process.exitCode = await runOpsScript({ script: createSetTemporaryPasswordScript(config), argv: process.argv.slice(2), config });
278
+ ```
279
+
280
+ `node set-temporary-password.mjs --email=owner@example.com` shows what it would end and rolls back
281
+ (the printed password is not stored); `--commit` writes and prints the password to hand over. Send
282
+ it only to the account's own address, and ask the owner to change it after logging in: the module
283
+ does not force a change.
284
+
285
+ **Password reset.** Pass a sender, and the login form links to the request page. With
286
+ `@softure-ai/mailing` enabled, `mailingResetSender()` is that sender:
287
+
288
+ ```ts
289
+ import { auth } from "@softure-ai/auth";
290
+ import { mailingResetSender } from "@softure-ai/auth/mailing";
291
+ import { mailing, resend } from "@softure-ai/mailing";
292
+
293
+ modules: [
294
+ auth({ passwordReset: { send: mailingResetSender() } }),
295
+ mailing({ from: "Acme <hello@mail.acme.com>", provider: resend() }),
296
+ ];
297
+ ```
298
+
299
+ It mails the account's address in the app's locale: subject, a plain-text body with the link and an
300
+ HTML body with it as an anchor, from `resetMail` in the dictionaries (section 9), with how long the
301
+ link works (`ttlMinutes`, in the locale's plural form). It is a transactional mail: no unsubscribe
302
+ link. It reads the registered config (`registerSoftureConfig`) when it runs; a failed send
303
+ (`mailing.rejected`, `mailing.unavailable`, or mailing not enabled) is logged like any sender error.
304
+ `renderPasswordResetMail(messages, locale, { link, ttlMinutes })` renders the same mail for an app
305
+ that sends it another way. Any other sender works too:
306
+
307
+ ```ts
308
+ import { auth, consolePasswordResetSender } from "@softure-ai/auth";
309
+
310
+ auth({
311
+ passwordReset: {
312
+ // link: `${appOrigin}/reset-password?token=…`; details: { expiresAt, locale }
313
+ send: async (link, user, details) => {
314
+ await mailer.send({ to: user.email, template: "password-reset", data: { link, expiresAt: details.expiresAt }, locale: details.locale });
315
+ },
316
+ // in development only: send: consolePasswordResetSender (it refuses under NODE_ENV=production)
317
+ },
318
+ });
319
+ ```
320
+
321
+ - The request page answers the same for every email: the link is issued and the sender runs after
322
+ the response (Next's `after()`), so neither its time nor a failure shows. A sender error is logged
323
+ without the link. `password-reset-account` bounds how many links one address can receive.
324
+ - A link carries 32 random bytes; only their sha256 is stored. One link per account is pending: a
325
+ new request replaces it. It works for `ttlMinutes`, once. Opening it only checks it (mail scanners
326
+ open links too); submitting the new password consumes it, sets the password, ends **every**
327
+ session of the account and sends the user to the login page, which confirms the change.
328
+ - A normal password change cancels a pending link.
329
+ - The link is built on `appOrigin`, never on the request's Host header. A multi-host app keeps the
330
+ link's path and query and swaps the origin in its sender, from what it knows about the user.
331
+ - The reset page's referrer policy is `same-origin`, so the token in its URL never reaches another
332
+ site. It still lands in your own access logs; it works once and expires.
333
+ - `requestPasswordReset`, `deliverPasswordReset`, `resetPassword`, `findPasswordResetUser` and
334
+ `prunePasswordResets` in `@softure-ai/auth/server` do the same for your own flows.
335
+
336
+ **Your own forms.** `@softure-ai/auth/ui` exports `LoginForm`, `RegisterForm`,
337
+ `ChangePasswordForm`, `ForgotPasswordForm` and `ResetPasswordForm`; pass them the actions from
338
+ `@softure-ai/auth/next`. `RegisterForm` takes `consentLabel` and `extraFields` like
339
+ `createRegisterPage`.
340
+
341
+ **Tests.** `createTestAccount(db, { email, password, roles?, scrypt? })` from `@softure-ai/auth/testing`
342
+ writes an account and its role rows in one transaction, hashed as registration hashes it, and returns
343
+ the `AuthUser`. It is for tests that need an account but are not about registration: no `onRegistered`
344
+ hook runs (no consent row) and no session is opened, so the test signs in through the login form.
345
+ Pass the app's parameters, so the first login does not rehash:
346
+
347
+ ```ts
348
+ import { getAuthOptions } from "@softure-ai/auth/server";
349
+ import { createTestAccount } from "@softure-ai/auth/testing";
350
+
351
+ const user = await createTestAccount(handle.db, {
352
+ email: "ada@example.com",
353
+ password: "correct horse battery",
354
+ roles: ["admin"],
355
+ scrypt: getAuthOptions(config).password.scrypt,
356
+ });
357
+ ```
358
+
359
+ An invalid or taken email throws. The entry is server-only and never imported by the module itself.
360
+
361
+ ## 5. Migrations and tables
362
+
363
+ `softure migrate` applies `migrations/0001_create_users_and_sessions.sql`,
364
+ `0002_create_user_roles.sql`, `0003_create_password_resets.sql` and
365
+ `0004_index_users_created_at.sql` (an index on `users.created_at` for billing's reminder mail)
366
+ after security's.
367
+
368
+ - `auth.users(id uuid, email, password_hash, created_at, password_changed_at)`: the email is stored
369
+ trimmed and lowercased (`CHECK`), unique; the hash must be a `scrypt$…` string.
370
+ - `auth.sessions(token_hash, user_id → users ON DELETE CASCADE, created_at, expires_at)`: only the
371
+ sha256 of the cookie token is stored.
372
+ - `auth.user_roles(user_id → users ON DELETE CASCADE, role, granted_at)`, primary key
373
+ `(user_id, role)`; the role name has the declared shape (`CHECK`).
374
+ - `auth.password_resets(user_id → users ON DELETE CASCADE, token_hash, created_at, expires_at)`,
375
+ primary key `user_id` (one pending link per account), unique `token_hash` (sha256 only).
376
+
377
+ Your own tables reference `users.id` (exported as the Drizzle table `users`; roles as `userRoles`); keep app columns in
378
+ your own 1:1 table, never in `auth.users`. Expired sessions of a user are deleted at their next
379
+ login; `pruneSessions(ctx)` from `@softure-ai/auth/server` deletes all of them for a scheduled job,
380
+ and `prunePasswordResets(ctx)` does the same for expired reset links.
381
+
382
+ **Adopting existing sessions.** An app that moves to this module from its own auth can keep its
383
+ users, its password hashes when they are `scrypt$N$r$p$salt$key` strings, and its sessions when it
384
+ stored them as the sha256 hex of the token. Its cookie has another name and its tokens another
385
+ shape, so without more every user logs in once after the switch. To keep them signed in, declare
386
+ the old cookie:
387
+
388
+ ```ts
389
+ auth({ legacySession: { cookieName: "session", tokenPattern: /[0-9a-f]{64}/ } });
390
+ ```
391
+
392
+ `tokenPattern` describes the whole token (the module anchors it) and must not use the `g` or `y`
393
+ flag. While the current cookie is absent the old one is read, its token looked up by the same
394
+ sha256, and the route guard counts it. The next login, register or logout ends that session and
395
+ removes the old cookie (`Path=/` and `cookie.domain`; an old cookie set on another path or domain
396
+ stays until it expires, its session already ended). Legacy sessions keep their own expiry. Remove
397
+ the option once the longest of them has expired.
398
+
399
+ A password hashed from input that was not NFC still verifies: a login tries the input as given when
400
+ its NFC form fails, then rehashes it in NFC.
401
+
402
+ ## 6. Environment variables
403
+
404
+ | Name | Required | Meaning |
405
+ | --- | --- | --- |
406
+ | `SOFTURE_SWITCH_AUTH_REGISTRATION_CLOSED` | no | `true` / `1` closes registration, `false` / `0` opens it, over the declared default. Any other value closes it and logs the variable name. When the app defines the switch in `@softure-ai/feature-switches`, that module reads this variable by its own rules (`on` / `off` too; an unreadable value gives the fail mode). |
407
+
408
+ ## 7. Switches
409
+
410
+ `auth.registration_closed`: when on, the register page shows a notice instead of the form, the
411
+ login page drops its register link, and the register action refuses with `auth.registration_closed`.
412
+
413
+ Auth reads it through `readSwitch` of `@softure-ai/core`. When the app defines it in
414
+ `@softure-ai/feature-switches`, the switches panel flips it and the stored value applies from the
415
+ next request (environment override, stored value, default, fail mode, as that module resolves
416
+ them). Define it with `failMode: "open"`, so a failed read keeps registration closed:
417
+
418
+ ```ts
419
+ featureSwitches({
420
+ switches: [{ name: REGISTRATION_CLOSED_SWITCH, label: { en: "Registration closed" }, default: false, failMode: "open" }],
421
+ }),
422
+ ```
423
+
424
+ Without feature-switches, or while the app does not define the switch there, its value is the
425
+ `registrationClosed` option overridden by the env variable above. `isRegistrationClosed(ctx)` from
426
+ `@softure-ai/auth/server` is async and gives the same answer the pages and the action use.
427
+
428
+ ## 8. Appearance
429
+
430
+ Pages and forms are built from `@softure-ai/ui` (Card, fields, Checkbox, Button) and use only its
431
+ compiled classes, so `@softure-ai/ui/styles.css` styles them and the `--sft-*` tokens theme them.
432
+ Each form takes `classNames` for its slots (`root`, `form`, `footer`, `link`, `notice`, and `submit`
433
+ for the submit button's class), `submitVariant` (a `Button` variant, `primary` by default) and
434
+ `unstyled`; pages are server components you can replace with your own page around the forms.
435
+
436
+ ## 9. Copy
437
+
438
+ `authMessages.en` and `authMessages.pl`, overridable per locale:
439
+ `auth({ messages: { en: { login: { title: "Sign in to Acme" } } } })`. Groups: `fields`, `login`,
440
+ `register`, `changePassword`, `forgotPassword`, `resetPassword`, `resetMail` (the reset mail of
441
+ `mailingResetSender()`; `minutes` holds plural forms), `logout`, and `errors.{auth,security,core}` keyed by the error code
442
+ (`auth.invalid_credentials` → `errors.auth.invalid_credentials`). `getAuthErrorMessage(messages, code)`
443
+ looks one up.
444
+
445
+ ## 10. Hooks
446
+
447
+ `onRegistered({ user, consent, fields }, ctx)`: after the user row is inserted, in the same
448
+ transaction (`ctx.db` is the transaction). `consent` is `{ acceptedAt }`, or `null` with
449
+ `requireConsent: false`. `fields` holds the declared `registrationFields` the form sent, by name
450
+ (strings cut to 512 characters, empty ones left out). They come from the client, and a link can set
451
+ a carried one, so validate them before you store them. The hook runs inside the register action,
452
+ so it can also read the request (`headers()`, `cookies()` from `next/headers`). A thrown error rolls the registration back and the user sees a generic
453
+ failure. `@softure-ai/privacy` stores the consent through it.
454
+
455
+ `passwordReset.send(link, user, details)`: after a reset request is answered, for an existing
456
+ account only (section 4, "Password reset"). `mailingResetSender()` from `@softure-ai/auth/mailing`
457
+ plugs `@softure-ai/mailing` in here.
458
+
459
+ ## 11. GDPR
460
+
461
+ The module stores an email, a password hash, session rows, role rows and pending reset rows. It
462
+ contributes to `@softure-ai/privacy` (`privacy` flags on):
463
+
464
+ - **Export** (`exportAuthUserData`): the account (id, email, `createdAt`, `passwordChangedAt`),
465
+ stored roles with their grant dates, sessions (created and expiry dates) and a pending reset link
466
+ (created and expiry dates). Never the password hash or a token hash. A role held through
467
+ `adminEmails` is configuration, so it is not in the export.
468
+ - **Deletion** (`deleteAuthUserData`): the user's sessions, pending reset, roles and then the
469
+ account row, so every session ends with the account. Privacy runs auth after the modules that
470
+ depend on it, and the app's contributors before all modules.
471
+
472
+ `isCurrentPassword(ctx, userId, password)` (`/server`) checks the password again before an action
473
+ that cannot be undone, such as the account deletion; the caller counts the attempt first.
474
+
475
+ Rate limit rows of `security` hold only SHA-256 prefixes of the email and user id
476
+ (`subjectKey`), pruned two windows after they start; they are not exported or deleted.
477
+
478
+ ## 12. Limitations / known gaps
479
+
480
+ - Sessions have a fixed lifetime; there is no sliding renewal and no "remember me".
481
+ - A password change keeps the session that made it (and ends every other one); the token itself
482
+ is not rotated. The new password must differ from the current one (`auth.password_unchanged`). Login and register end the session the browser held before.
483
+ - No email verification, so `adminEmails` trusts whoever registers a listed email first. (A reset
484
+ link goes to the account's email, so its owner can take the account back.)
485
+ - Roles are flat: no hierarchy and no permissions per role; no UI to manage them (the scripts do).
486
+ - The guard checks cookie presence only; the session is verified by `requireUser`.
487
+ - A `next` path longer than 8192 characters is replaced by the default target, with a warning in
488
+ the log that names its length.
489
+ - A temporary password from the script is not forced to change at the next login.
490
+ - A registration attempt reveals whether an email has an account (`auth.email_taken`); the
491
+ `register` rate limit bounds how fast anyone can ask.
@@ -0,0 +1,46 @@
1
+ import type { CoreErrorCode } from "@softure-ai/core";
2
+ import type { SecurityErrorCode } from "@softure-ai/security";
3
+ export type AuthErrorCode = "auth.invalid_credentials" | "auth.email_invalid" | "auth.email_taken" | "auth.password_too_short" | "auth.password_too_long" | "auth.consent_required" | "auth.registration_closed" | "auth.current_password_invalid" | "auth.password_unchanged" | "auth.unauthenticated" | "auth.forbidden" | "auth.reset_token_invalid" | "auth.password_reset_unavailable";
4
+ /** Every code an auth form can show: its own, the rate limiter's and the generic ones. */
5
+ export type AuthFormErrorCode = AuthErrorCode | Extract<SecurityErrorCode, "security.rate_limited" | "security.client_unidentified"> | CoreErrorCode;
6
+ /** A signed-up account, as the app sees it. The password hash never leaves the module. */
7
+ export interface AuthUser {
8
+ readonly id: string;
9
+ readonly email: string;
10
+ readonly createdAt: Date;
11
+ }
12
+ /** A session just opened: the token goes into the cookie and is never stored. */
13
+ export interface NewSession {
14
+ readonly token: string;
15
+ readonly expiresAt: Date;
16
+ }
17
+ /** A successful register or login. */
18
+ export interface SignedIn {
19
+ readonly user: AuthUser;
20
+ readonly session: NewSession;
21
+ }
22
+ /** What `onRegistered` receives. `consent` is null when the app turned `requireConsent` off. */
23
+ export interface RegisteredEvent {
24
+ readonly user: AuthUser;
25
+ readonly consent: {
26
+ readonly acceptedAt: Date;
27
+ } | null;
28
+ /** The declared `registrationFields` the form sent, by name; client input, so validate it. */
29
+ readonly fields: Readonly<Record<string, string>>;
30
+ }
31
+ /** The fields of the auth forms that can carry their own error. */
32
+ export type AuthFormField = "email" | "password" | "currentPassword" | "newPassword" | "consent";
33
+ /**
34
+ * What an auth server action returns to its form (`useActionState`). A successful login or
35
+ * register redirects instead of returning; a password change returns `ok`.
36
+ */
37
+ export interface AuthFormState {
38
+ readonly status: "idle" | "ok" | "error";
39
+ /** The error to show; when `field` is set it is shown at that field. */
40
+ readonly error?: AuthFormErrorCode;
41
+ readonly field?: AuthFormField;
42
+ /** The submitted email, so a rejected form keeps it (passwords are never sent back). */
43
+ readonly email?: string;
44
+ }
45
+ export declare const INITIAL_AUTH_FORM_STATE: AuthFormState;
46
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,MAAM,aAAa,GACrB,0BAA0B,GAC1B,oBAAoB,GACpB,kBAAkB,GAClB,yBAAyB,GACzB,wBAAwB,GACxB,uBAAuB,GACvB,0BAA0B,GAC1B,+BAA+B,GAC/B,yBAAyB,GACzB,sBAAsB,GACtB,gBAAgB,GAChB,0BAA0B,GAC1B,iCAAiC,CAAC;AAEtC,0FAA0F;AAC1F,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG,OAAO,CAAC,iBAAiB,EAAE,uBAAuB,GAAG,8BAA8B,CAAC,GAAG,aAAa,CAAC;AAErJ,0FAA0F;AAC1F,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CAC1B;AAED,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CAC1B;AAED,sCAAsC;AACtC,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;CAC9B;AAED,gGAAgG;AAChG,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IACvD,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACnD;AAED,mEAAmE;AACnE,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,iBAAiB,GAAG,aAAa,GAAG,SAAS,CAAC;AAEjG;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC;IACzC,wEAAwE;IACxE,QAAQ,CAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC/B,wFAAwF;IACxF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,uBAAuB,EAAE,aAAkC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const INITIAL_AUTH_FORM_STATE = { status: "idle" };
2
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAkEA,MAAM,CAAC,MAAM,uBAAuB,GAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC"}