@softure-ai/auth 0.0.0-stage → 0.1.5
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/LICENSE +21 -0
- package/README.md +381 -2
- package/dist/contract.d.ts +44 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +2 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +188 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/dist/mailing/index.d.ts +2 -0
- package/dist/mailing/index.d.ts.map +1 -0
- package/dist/mailing/index.js +4 -0
- package/dist/mailing/index.js.map +1 -0
- package/dist/mailing/reset-mail.d.ts +27 -0
- package/dist/mailing/reset-mail.d.ts.map +1 -0
- package/dist/mailing/reset-mail.js +55 -0
- package/dist/mailing/reset-mail.js.map +1 -0
- package/dist/messages/en.d.ts +97 -0
- package/dist/messages/en.d.ts.map +1 -0
- package/dist/messages/en.js +92 -0
- package/dist/messages/en.js.map +1 -0
- package/dist/messages/index.d.ts +199 -0
- package/dist/messages/index.d.ts.map +1 -0
- package/dist/messages/index.js +11 -0
- package/dist/messages/index.js.map +1 -0
- package/dist/messages/pl.d.ts +3 -0
- package/dist/messages/pl.d.ts.map +1 -0
- package/dist/messages/pl.js +91 -0
- package/dist/messages/pl.js.map +1 -0
- package/dist/next/actions.d.ts +19 -0
- package/dist/next/actions.d.ts.map +1 -0
- package/dist/next/actions.js +210 -0
- package/dist/next/actions.js.map +1 -0
- package/dist/next/context.d.ts +4 -0
- package/dist/next/context.d.ts.map +1 -0
- package/dist/next/context.js +13 -0
- package/dist/next/context.js.map +1 -0
- package/dist/next/current-user.d.ts +34 -0
- package/dist/next/current-user.d.ts.map +1 -0
- package/dist/next/current-user.js +77 -0
- package/dist/next/current-user.js.map +1 -0
- package/dist/next/index.d.ts +8 -0
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +9 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/logout-button.d.ts +7 -0
- package/dist/next/logout-button.d.ts.map +1 -0
- package/dist/next/logout-button.js +12 -0
- package/dist/next/logout-button.js.map +1 -0
- package/dist/next/messages.d.ts +5 -0
- package/dist/next/messages.d.ts.map +1 -0
- package/dist/next/messages.js +7 -0
- package/dist/next/messages.js.map +1 -0
- package/dist/next/pages.d.ts +18 -0
- package/dist/next/pages.d.ts.map +1 -0
- package/dist/next/pages.js +92 -0
- package/dist/next/pages.js.map +1 -0
- package/dist/next/params.d.ts +3 -0
- package/dist/next/params.d.ts.map +1 -0
- package/dist/next/params.js +4 -0
- package/dist/next/params.js.map +1 -0
- package/dist/next/route.d.ts +3 -0
- package/dist/next/route.d.ts.map +1 -0
- package/dist/next/route.js +17 -0
- package/dist/next/route.js.map +1 -0
- package/dist/next/search-params.d.ts +5 -0
- package/dist/next/search-params.d.ts.map +1 -0
- package/dist/next/search-params.js +13 -0
- package/dist/next/search-params.js.map +1 -0
- package/dist/next/session-cookie.d.ts +8 -0
- package/dist/next/session-cookie.d.ts.map +1 -0
- package/dist/next/session-cookie.js +34 -0
- package/dist/next/session-cookie.js.map +1 -0
- package/dist/options.d.ts +63 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +74 -0
- package/dist/options.js.map +1 -0
- package/dist/password-reset-sender.d.ts +21 -0
- package/dist/password-reset-sender.d.ts.map +1 -0
- package/dist/password-reset-sender.js +12 -0
- package/dist/password-reset-sender.js.map +1 -0
- package/dist/proxy/index.d.ts +9 -0
- package/dist/proxy/index.d.ts.map +1 -0
- package/dist/proxy/index.js +41 -0
- package/dist/proxy/index.js.map +1 -0
- package/dist/redirect-target.d.ts +7 -0
- package/dist/redirect-target.d.ts.map +1 -0
- package/dist/redirect-target.js +25 -0
- package/dist/redirect-target.js.map +1 -0
- package/dist/roles.d.ts +5 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/roles.js +6 -0
- package/dist/roles.js.map +1 -0
- package/dist/safe-next-path.d.ts +3 -0
- package/dist/safe-next-path.d.ts.map +1 -0
- package/dist/safe-next-path.js +19 -0
- package/dist/safe-next-path.js.map +1 -0
- package/dist/schema.d.ts +302 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +37 -0
- package/dist/schema.js.map +1 -0
- package/dist/scripts/index.d.ts +2 -0
- package/dist/scripts/index.d.ts.map +1 -0
- package/dist/scripts/index.js +3 -0
- package/dist/scripts/index.js.map +1 -0
- package/dist/scripts/role-scripts.d.ts +15 -0
- package/dist/scripts/role-scripts.d.ts.map +1 -0
- package/dist/scripts/role-scripts.js +76 -0
- package/dist/scripts/role-scripts.js.map +1 -0
- package/dist/server/change-password.d.ts +14 -0
- package/dist/server/change-password.d.ts.map +1 -0
- package/dist/server/change-password.js +47 -0
- package/dist/server/change-password.js.map +1 -0
- package/dist/server/health.d.ts +3 -0
- package/dist/server/health.d.ts.map +1 -0
- package/dist/server/health.js +15 -0
- package/dist/server/health.js.map +1 -0
- package/dist/server/index.d.ts +12 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +14 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/login.d.ts +14 -0
- package/dist/server/login.d.ts.map +1 -0
- package/dist/server/login.js +49 -0
- package/dist/server/login.js.map +1 -0
- package/dist/server/options.d.ts +17 -0
- package/dist/server/options.d.ts.map +1 -0
- package/dist/server/options.js +36 -0
- package/dist/server/options.js.map +1 -0
- package/dist/server/password-reset.d.ts +54 -0
- package/dist/server/password-reset.d.ts.map +1 -0
- package/dist/server/password-reset.js +134 -0
- package/dist/server/password-reset.js.map +1 -0
- package/dist/server/password.d.ts +18 -0
- package/dist/server/password.d.ts.map +1 -0
- package/dist/server/password.js +77 -0
- package/dist/server/password.js.map +1 -0
- package/dist/server/privacy.d.ts +33 -0
- package/dist/server/privacy.d.ts.map +1 -0
- package/dist/server/privacy.js +52 -0
- package/dist/server/privacy.js.map +1 -0
- package/dist/server/rate-limits.d.ts +21 -0
- package/dist/server/rate-limits.d.ts.map +1 -0
- package/dist/server/rate-limits.js +39 -0
- package/dist/server/rate-limits.js.map +1 -0
- package/dist/server/reauthenticate.d.ts +7 -0
- package/dist/server/reauthenticate.d.ts.map +1 -0
- package/dist/server/reauthenticate.js +16 -0
- package/dist/server/reauthenticate.js.map +1 -0
- package/dist/server/register.d.ts +21 -0
- package/dist/server/register.d.ts.map +1 -0
- package/dist/server/register.js +52 -0
- package/dist/server/register.js.map +1 -0
- package/dist/server/roles.d.ts +25 -0
- package/dist/server/roles.d.ts.map +1 -0
- package/dist/server/roles.js +56 -0
- package/dist/server/roles.js.map +1 -0
- package/dist/server/session-token.d.ts +8 -0
- package/dist/server/session-token.d.ts.map +1 -0
- package/dist/server/session-token.js +18 -0
- package/dist/server/session-token.js.map +1 -0
- package/dist/server/sessions.d.ts +15 -0
- package/dist/server/sessions.d.ts.map +1 -0
- package/dist/server/sessions.js +41 -0
- package/dist/server/sessions.js.map +1 -0
- package/dist/server/switches.d.ts +9 -0
- package/dist/server/switches.d.ts.map +1 -0
- package/dist/server/switches.js +34 -0
- package/dist/server/switches.js.map +1 -0
- package/dist/server/validation.d.ts +10 -0
- package/dist/server/validation.d.ts.map +1 -0
- package/dist/server/validation.js +32 -0
- package/dist/server/validation.js.map +1 -0
- package/dist/session-cookie.d.ts +14 -0
- package/dist/session-cookie.d.ts.map +1 -0
- package/dist/session-cookie.js +31 -0
- package/dist/session-cookie.js.map +1 -0
- package/dist/ui/auth-forms.d.ts +57 -0
- package/dist/ui/auth-forms.d.ts.map +1 -0
- package/dist/ui/auth-forms.js +65 -0
- package/dist/ui/auth-forms.js.map +1 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +4 -0
- package/dist/ui/index.js.map +1 -0
- package/migrations/0001_create_users_and_sessions.sql +25 -0
- package/migrations/0002_create_user_roles.sql +10 -0
- package/migrations/0003_create_password_resets.sql +15 -0
- package/migrations/0004_index_users_created_at.sql +5 -0
- package/module.json +34 -0
- package/package.json +85 -4
- package/src/contract.ts +64 -0
- package/src/index.ts +100 -0
- package/src/mailing/index.ts +3 -0
- package/src/mailing/reset-mail.ts +73 -0
- package/src/messages/en.ts +91 -0
- package/src/messages/index.ts +15 -0
- package/src/messages/pl.ts +92 -0
- package/src/next/actions.ts +216 -0
- package/src/next/context.ts +14 -0
- package/src/next/current-user.ts +90 -0
- package/src/next/index.ts +24 -0
- package/src/next/logout-button.tsx +22 -0
- package/src/next/messages.ts +9 -0
- package/src/next/next-modules.d.ts +16 -0
- package/src/next/pages.tsx +179 -0
- package/src/next/params.ts +4 -0
- package/src/next/route.ts +17 -0
- package/src/next/search-params.ts +14 -0
- package/src/next/session-cookie.ts +39 -0
- package/src/options.ts +108 -0
- package/src/password-reset-sender.ts +33 -0
- package/src/proxy/index.ts +58 -0
- package/src/redirect-target.ts +24 -0
- package/src/roles.ts +7 -0
- package/src/safe-next-path.ts +15 -0
- package/src/schema.ts +45 -0
- package/src/scripts/index.ts +2 -0
- package/src/scripts/role-scripts.ts +98 -0
- package/src/server/change-password.ts +61 -0
- package/src/server/health.ts +16 -0
- package/src/server/index.ts +38 -0
- package/src/server/login.ts +61 -0
- package/src/server/options.ts +49 -0
- package/src/server/password-reset.ts +164 -0
- package/src/server/password.ts +90 -0
- package/src/server/privacy.ts +70 -0
- package/src/server/rate-limits.ts +44 -0
- package/src/server/reauthenticate.ts +16 -0
- package/src/server/register.ts +72 -0
- package/src/server/roles.ts +72 -0
- package/src/server/session-token.ts +21 -0
- package/src/server/sessions.ts +50 -0
- package/src/server/switches.ts +31 -0
- package/src/server/validation.ts +37 -0
- package/src/session-cookie.ts +47 -0
- package/src/ui/auth-forms.tsx +364 -0
- package/src/ui/index.ts +16 -0
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,382 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @softure-ai/auth
|
|
2
2
|
|
|
3
|
-
|
|
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. Built from
|
|
6
|
+
FIRE_TRACKER's auth (`src/lib/{password,session}.ts`, `src/db/sessions.ts`,
|
|
7
|
+
`src/app/actions/do-auth.ts`, `src/proxy.ts`), with the rate limiter of `@softure-ai/security`
|
|
8
|
+
and the route guard separated from channel tagging.
|
|
9
|
+
|
|
10
|
+
## 1. What it provides
|
|
11
|
+
|
|
12
|
+
Users and sessions in the `auth` schema, scrypt password hashes, opaque session cookies, register,
|
|
13
|
+
login, logout, password change and password reset as server actions and pages, `getCurrentUser` / `requireUser`
|
|
14
|
+
for server code, roles (`requireRole`, `authorizeRole`, `hasRole`, and `grant-role` /
|
|
15
|
+
`revoke-role` scripts), `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()`).
|
|
19
|
+
|
|
20
|
+
## 2. Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @softure-ai/auth @softure-ai/security @softure-ai/core @softure-ai/db @softure-ai/ui drizzle-orm
|
|
24
|
+
# for the role scripts (section 4, "Roles"), already a dependency of auth:
|
|
25
|
+
npm install @softure-ai/ops
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Peer dependencies: `next` 16, `react` 19, `drizzle-orm`; `@softure-ai/mailing` (optional) for
|
|
29
|
+
`@softure-ai/auth/mailing`.
|
|
30
|
+
|
|
31
|
+
## 3. Configuration
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { defineSoftureConfig } from "@softure-ai/core";
|
|
35
|
+
import { registerSoftureConfig } from "@softure-ai/core/next";
|
|
36
|
+
import { auth, AUTH_RATE_LIMIT_BUCKETS } from "@softure-ai/auth";
|
|
37
|
+
import { cloudflareIp, security } from "@softure-ai/security";
|
|
38
|
+
|
|
39
|
+
const config = defineSoftureConfig({
|
|
40
|
+
database: { url: process.env.DATABASE_URL! },
|
|
41
|
+
locale: "pl",
|
|
42
|
+
timezone: "Europe/Warsaw",
|
|
43
|
+
appOrigin: process.env.APP_ORIGIN!,
|
|
44
|
+
modules: [
|
|
45
|
+
// auth counts attempts in these four buckets; change the numbers, keep the names.
|
|
46
|
+
security({ clientIp: cloudflareIp(), buckets: { ...AUTH_RATE_LIMIT_BUCKETS } }),
|
|
47
|
+
auth({
|
|
48
|
+
routes: { afterLogin: "/dashboard" },
|
|
49
|
+
password: { minLength: 12 },
|
|
50
|
+
onRegistered: async ({ user, consent }, ctx) => {
|
|
51
|
+
// Runs in the registration transaction: throw to roll the account back.
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
registerSoftureConfig(config);
|
|
58
|
+
export default config;
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
| Option | Type | Default | Meaning |
|
|
62
|
+
| --- | --- | --- | --- |
|
|
63
|
+
| `password.minLength` | `number` (8-128) | `10` | Shortest new password, in characters. The longest is 1024. |
|
|
64
|
+
| `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. |
|
|
65
|
+
| `session.ttlDays` | `number` (1-365) | `30` | Session lifetime from login. It is not extended by use. |
|
|
66
|
+
| `cookie.name` | `string` | `"softure_session"` | Base name of the session cookie (see below). |
|
|
67
|
+
| `cookie.domain` | `string` | none (host-only) | Share the session with subdomains, e.g. `example.com` for the apex and `app.example.com`. |
|
|
68
|
+
| `cookie.secure` | `boolean` | `appOrigin` is https | Send the cookie over HTTPS only. |
|
|
69
|
+
| `requireConsent` | `boolean` | `true` | Registration needs the consent checkbox. |
|
|
70
|
+
| `registrationClosed` | `boolean` | `false` | Declared default of the `auth.registration_closed` switch. |
|
|
71
|
+
| `roles` | `string[]` | `[]` | Role names the app checks besides `admin` (always declared): `a-z`, `0-9`, `_`, `-`, at most 32. |
|
|
72
|
+
| `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"). |
|
|
73
|
+
| `onRegistered` | `(event, ctx) => Promise<void>` | none | Called after the account is created, inside the same transaction. |
|
|
74
|
+
| `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. |
|
|
75
|
+
| `passwordReset.send` | `(link, user, details) => Promise<void>` | none | Delivers reset links (section 4, "Password reset"). Without it password reset is off. |
|
|
76
|
+
| `passwordReset.ttlMinutes` | `number` (5-1440) | `60` | How long a reset link works. |
|
|
77
|
+
| `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. |
|
|
78
|
+
| `messages` | partial `pl` / `en` dictionaries | built in | Copy overrides (section 9). |
|
|
79
|
+
|
|
80
|
+
**Cookie.** Always `HttpOnly`, `SameSite=Lax`, `Path=/`, `Max-Age` = the TTL. A secure cookie gets
|
|
81
|
+
the prefix browsers enforce: `__Host-softure_session` when it is host-only, `__Secure-softure_session`
|
|
82
|
+
with `cookie.domain`. Over plain HTTP (local development) it keeps the bare name.
|
|
83
|
+
|
|
84
|
+
**Rate limits** (`AUTH_RATE_LIMIT_BUCKETS`, configured in `security`): `register` 5 and `login` 50
|
|
85
|
+
per client address, `login-account` 10 per email, `change-password` 10 per user,
|
|
86
|
+
`password-reset` 10 (link requests) and `password-reset-confirm` 10 (new passwords) per client
|
|
87
|
+
address, `password-reset-account` 3 per email (the mails one address can get), each per 15
|
|
88
|
+
minutes. Attempts are counted before any password is hashed. A successful login forgets the
|
|
89
|
+
email's failed attempts, not the address's. `login-account` is a lockout by design: ten wrong
|
|
90
|
+
passwords for one email, from any addresses, block logins to that account for the rest of the
|
|
91
|
+
window, the owner's included. Raise its limit if that trade-off is wrong for your app. Auth checks
|
|
92
|
+
at its first call that all seven buckets exist and names the missing ones. A request whose client address cannot be resolved is
|
|
93
|
+
refused (`security.client_unidentified`); see the security README for resolvers.
|
|
94
|
+
|
|
95
|
+
## 4. Mounting
|
|
96
|
+
|
|
97
|
+
One line per file, owned by the app (docs/02 §8):
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
// app/login/page.tsx
|
|
101
|
+
export { LoginPage as default } from "@softure-ai/auth/next";
|
|
102
|
+
// app/register/page.tsx
|
|
103
|
+
export { RegisterPage as default } from "@softure-ai/auth/next";
|
|
104
|
+
// app/account/password/page.tsx
|
|
105
|
+
export { ChangePasswordPage as default } from "@softure-ai/auth/next";
|
|
106
|
+
// app/forgot-password/page.tsx and app/reset-password/page.tsx (with passwordReset.send)
|
|
107
|
+
export { ForgotPasswordPage as default } from "@softure-ai/auth/next";
|
|
108
|
+
export { ResetPasswordPage as default } from "@softure-ai/auth/next";
|
|
109
|
+
// app/api/auth/session/route.ts: { user: { id, email } | null }, never cached
|
|
110
|
+
export { getSessionRoute as GET } from "@softure-ai/auth/next";
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The server actions (`loginAction`, `registerAction`, `changePasswordAction`, `forgotPasswordAction`,
|
|
114
|
+
`resetPasswordAction`, `logoutAction`) need no mounting. In your own pages and layouts:
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
import { getCurrentUser, LogoutButton, requireUser } from "@softure-ai/auth/next";
|
|
118
|
+
|
|
119
|
+
export default async function AccountPage() {
|
|
120
|
+
const user = await requireUser(); // redirects to the login page without a live session
|
|
121
|
+
return (
|
|
122
|
+
<main>
|
|
123
|
+
<p>{user.email}</p>
|
|
124
|
+
<LogoutButton />
|
|
125
|
+
</main>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`requireUser({ next: "/account" })` brings the user back after login; `getCurrentUser()` returns
|
|
131
|
+
the user or `null`. Both read the session once per request. The redirect to login goes through the
|
|
132
|
+
app's `rewriteRedirect` (options table); a page outside the proxy's guard passes its own search
|
|
133
|
+
params so the login URL can keep its channel tag:
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
export default async function SettingsPage({ searchParams }: { searchParams: Promise<Record<string, string | string[] | undefined>> }) {
|
|
137
|
+
const user = await requireUser({ next: "/settings", searchParams: await searchParams });
|
|
138
|
+
// …
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Private prefixes still belong behind the route guard below; the option covers the pages outside it
|
|
143
|
+
(billing's payment page passes its parameters).
|
|
144
|
+
|
|
145
|
+
**Route guard.** `createAuthGuard` returns `(request) => Response | null`: a redirect to the login
|
|
146
|
+
page (with `?next=`) for a protected path without a session cookie, `null` otherwise. It only
|
|
147
|
+
checks that the cookie is present, so **every private page and action still calls
|
|
148
|
+
`requireUser`**: the guard is a convenience, not the access check. Paths are compared decoded and
|
|
149
|
+
lowercased (`/%61ccount` and `/ACCOUNT` are guarded like `/account`). It imports nothing from Next,
|
|
150
|
+
so it chains with other proxy pieces:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
// proxy.ts
|
|
154
|
+
import { createAuthGuard } from "@softure-ai/auth/proxy";
|
|
155
|
+
import { NextResponse, type NextRequest } from "next/server";
|
|
156
|
+
import softureConfig from "./softure.config";
|
|
157
|
+
|
|
158
|
+
const guard = createAuthGuard(softureConfig, { protect: ["/account", "/dashboard"] });
|
|
159
|
+
|
|
160
|
+
export function proxy(request: NextRequest) {
|
|
161
|
+
return guard(request) ?? NextResponse.next();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Static files never need the guard.
|
|
165
|
+
export const config = { matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"] };
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
(Name the imported SOFTURE config differently, e.g. `softureConfig`, when `proxy.ts` also exports
|
|
169
|
+
Next's `config`.)
|
|
170
|
+
|
|
171
|
+
A protected prefix matches whole path segments (`/account` covers `/account/password`, not
|
|
172
|
+
`/accounting`). The change-password route is always protected. Redirects are built on `appOrigin`.
|
|
173
|
+
|
|
174
|
+
**Roles.** A role is a declared name (`admin`, plus `auth({ roles: ["editor"] })`) held by an
|
|
175
|
+
account: as a row in `auth.user_roles`, or, for `admin` only, through `adminEmails`. Nothing is
|
|
176
|
+
granted by default: with no admin listed and no rows, every admin-only surface stays closed.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
import { ADMIN_ROLE } from "@softure-ai/auth";
|
|
180
|
+
import { authorizeRole, hasRole, requireRole } from "@softure-ai/auth/next";
|
|
181
|
+
|
|
182
|
+
// app/admin/page.tsx (pages, layouts and route handlers)
|
|
183
|
+
export default async function AdminPage() {
|
|
184
|
+
await requireRole(ADMIN_ROLE); // anyone without the role, signed in or not: Next's "not found"
|
|
185
|
+
return <main>…</main>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// a server action: check first, before reading the form
|
|
189
|
+
export async function publishAction(formData: FormData) {
|
|
190
|
+
const admin = await authorizeRole(ADMIN_ROLE); // Ok<AuthUser> or Err<"auth.forbidden">
|
|
191
|
+
if (!admin.ok) return admin;
|
|
192
|
+
// …
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// UI only, e.g. whether to show a link; the target page checks again
|
|
196
|
+
const showAdminLink = await hasRole(ADMIN_ROLE);
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Roles are read once per request and never cached across requests or stored in the cookie, so a
|
|
200
|
+
revoke takes effect on the next request. Asking for a role the app did not declare throws: a typo
|
|
201
|
+
fails loudly instead of quietly closing (or opening) a surface. Keep admin paths out of the proxy
|
|
202
|
+
guard's `protect` list, or anonymous visitors are sent to the login page instead of "not found".
|
|
203
|
+
|
|
204
|
+
**The first admin.** Either list the email in `adminEmails` (register that account yourself
|
|
205
|
+
before the list is deployed, or keep registration closed meanwhile: whoever registers a listed email
|
|
206
|
+
first becomes admin), or, safer, grant the role with the ops script, which needs database access:
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
// scripts/grant-role.ts (bundled and run like the migrate step, @softure-ai/ops README)
|
|
210
|
+
import { createGrantRoleScript } from "@softure-ai/auth/scripts";
|
|
211
|
+
import { runOpsScript } from "@softure-ai/ops/scripts";
|
|
212
|
+
import config from "../softure.config";
|
|
213
|
+
|
|
214
|
+
process.exitCode = await runOpsScript({ script: createGrantRoleScript(config), argv: process.argv.slice(2), config });
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
`node grant-role.mjs --email=owner@example.com --role=admin` prints the account's roles before and
|
|
218
|
+
after (by user id, never the email) and rolls back; `--commit` writes. `createRevokeRoleScript`
|
|
219
|
+
is its pair. Both refuse an unknown email, an undeclared role, a role already granted (grant) or
|
|
220
|
+
not stored (revoke); an `admin` that comes from `adminEmails` is removed from the list, not by the
|
|
221
|
+
script. `grantRole`, `revokeRole` and `findUserRoles` in `@softure-ai/auth/server` do the same for
|
|
222
|
+
your own code.
|
|
223
|
+
|
|
224
|
+
**Password reset.** Pass a sender, and the login form links to the request page. With
|
|
225
|
+
`@softure-ai/mailing` enabled, `mailingResetSender()` is that sender:
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
import { auth } from "@softure-ai/auth";
|
|
229
|
+
import { mailingResetSender } from "@softure-ai/auth/mailing";
|
|
230
|
+
import { mailing, resend } from "@softure-ai/mailing";
|
|
231
|
+
|
|
232
|
+
modules: [
|
|
233
|
+
auth({ passwordReset: { send: mailingResetSender() } }),
|
|
234
|
+
mailing({ from: "Acme <hello@mail.acme.com>", provider: resend() }),
|
|
235
|
+
];
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
It mails the account's address in the app's locale: subject, a plain-text body with the link and an
|
|
239
|
+
HTML body with it as an anchor, from `resetMail` in the dictionaries (section 9), with how long the
|
|
240
|
+
link works (`ttlMinutes`, in the locale's plural form). It is a transactional mail: no unsubscribe
|
|
241
|
+
link. It reads the registered config (`registerSoftureConfig`) when it runs; a failed send
|
|
242
|
+
(`mailing.rejected`, `mailing.unavailable`, or mailing not enabled) is logged like any sender error.
|
|
243
|
+
`renderPasswordResetMail(messages, locale, { link, ttlMinutes })` renders the same mail for an app
|
|
244
|
+
that sends it another way. Any other sender works too:
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
import { auth, consolePasswordResetSender } from "@softure-ai/auth";
|
|
248
|
+
|
|
249
|
+
auth({
|
|
250
|
+
passwordReset: {
|
|
251
|
+
// link: `${appOrigin}/reset-password?token=…`; details: { expiresAt, locale }
|
|
252
|
+
send: async (link, user, details) => {
|
|
253
|
+
await mailer.send({ to: user.email, template: "password-reset", data: { link, expiresAt: details.expiresAt }, locale: details.locale });
|
|
254
|
+
},
|
|
255
|
+
// in development only: send: consolePasswordResetSender (it refuses under NODE_ENV=production)
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
- The request page answers the same for every email: the link is issued and the sender runs after
|
|
261
|
+
the response (Next's `after()`), so neither its time nor a failure shows. A sender error is logged
|
|
262
|
+
without the link. `password-reset-account` bounds how many links one address can receive.
|
|
263
|
+
- A link carries 32 random bytes; only their sha256 is stored. One link per account is pending: a
|
|
264
|
+
new request replaces it. It works for `ttlMinutes`, once. Opening it only checks it (mail scanners
|
|
265
|
+
open links too); submitting the new password consumes it, sets the password, ends **every**
|
|
266
|
+
session of the account and sends the user to the login page, which confirms the change.
|
|
267
|
+
- A normal password change cancels a pending link.
|
|
268
|
+
- The link is built on `appOrigin`, never on the request's Host header. A multi-host app keeps the
|
|
269
|
+
link's path and query and swaps the origin in its sender, from what it knows about the user.
|
|
270
|
+
- The reset page's referrer policy is `same-origin`, so the token in its URL never reaches another
|
|
271
|
+
site. It still lands in your own access logs; it works once and expires.
|
|
272
|
+
- `requestPasswordReset`, `deliverPasswordReset`, `resetPassword`, `findPasswordResetUser` and
|
|
273
|
+
`prunePasswordResets` in `@softure-ai/auth/server` do the same for your own flows.
|
|
274
|
+
|
|
275
|
+
**Your own forms.** `@softure-ai/auth/ui` exports `LoginForm`, `RegisterForm`,
|
|
276
|
+
`ChangePasswordForm`, `ForgotPasswordForm` and `ResetPasswordForm`; pass them the actions from
|
|
277
|
+
`@softure-ai/auth/next`.
|
|
278
|
+
|
|
279
|
+
## 5. Migrations and tables
|
|
280
|
+
|
|
281
|
+
`softure migrate` applies `migrations/0001_create_users_and_sessions.sql`,
|
|
282
|
+
`0002_create_user_roles.sql`, `0003_create_password_resets.sql` and
|
|
283
|
+
`0004_index_users_created_at.sql` (an index on `users.created_at` for billing's reminder mail)
|
|
284
|
+
after security's.
|
|
285
|
+
|
|
286
|
+
- `auth.users(id uuid, email, password_hash, created_at, password_changed_at)`: the email is stored
|
|
287
|
+
trimmed and lowercased (`CHECK`), unique; the hash must be a `scrypt$…` string.
|
|
288
|
+
- `auth.sessions(token_hash, user_id → users ON DELETE CASCADE, created_at, expires_at)`: only the
|
|
289
|
+
sha256 of the cookie token is stored.
|
|
290
|
+
- `auth.user_roles(user_id → users ON DELETE CASCADE, role, granted_at)`, primary key
|
|
291
|
+
`(user_id, role)`; the role name has the declared shape (`CHECK`).
|
|
292
|
+
- `auth.password_resets(user_id → users ON DELETE CASCADE, token_hash, created_at, expires_at)`,
|
|
293
|
+
primary key `user_id` (one pending link per account), unique `token_hash` (sha256 only).
|
|
294
|
+
|
|
295
|
+
Your own tables reference `users.id` (exported as the Drizzle table `users`; roles as `userRoles`); keep app columns in
|
|
296
|
+
your own 1:1 table, never in `auth.users`. Expired sessions of a user are deleted at their next
|
|
297
|
+
login; `pruneSessions(ctx)` from `@softure-ai/auth/server` deletes all of them for a scheduled job,
|
|
298
|
+
and `prunePasswordResets(ctx)` does the same for expired reset links.
|
|
299
|
+
|
|
300
|
+
## 6. Environment variables
|
|
301
|
+
|
|
302
|
+
| Name | Required | Meaning |
|
|
303
|
+
| --- | --- | --- |
|
|
304
|
+
| `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). |
|
|
305
|
+
|
|
306
|
+
## 7. Switches
|
|
307
|
+
|
|
308
|
+
`auth.registration_closed`: when on, the register page shows a notice instead of the form, the
|
|
309
|
+
login page drops its register link, and the register action refuses with `auth.registration_closed`.
|
|
310
|
+
|
|
311
|
+
Auth reads it through `readSwitch` of `@softure-ai/core`. When the app defines it in
|
|
312
|
+
`@softure-ai/feature-switches`, the switches panel flips it and the stored value applies from the
|
|
313
|
+
next request (environment override, stored value, default, fail mode, as that module resolves
|
|
314
|
+
them). Define it with `failMode: "open"`, so a failed read keeps registration closed:
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
featureSwitches({
|
|
318
|
+
switches: [{ name: REGISTRATION_CLOSED_SWITCH, label: { en: "Registration closed" }, default: false, failMode: "open" }],
|
|
319
|
+
}),
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Without feature-switches, or while the app does not define the switch there, its value is the
|
|
323
|
+
`registrationClosed` option overridden by the env variable above. `isRegistrationClosed(ctx)` from
|
|
324
|
+
`@softure-ai/auth/server` is async and gives the same answer the pages and the action use.
|
|
325
|
+
|
|
326
|
+
## 8. Appearance
|
|
327
|
+
|
|
328
|
+
Pages and forms are built from `@softure-ai/ui` (Card, fields, Checkbox, Button) and use only its
|
|
329
|
+
compiled classes, so `@softure-ai/ui/styles.css` styles them and the `--sft-*` tokens theme them.
|
|
330
|
+
Each form takes `classNames` for its slots (`root`, `form`, `footer`, `link`, `notice`) and
|
|
331
|
+
`unstyled`; pages are server components you can replace with your own page around the forms.
|
|
332
|
+
|
|
333
|
+
## 9. Copy
|
|
334
|
+
|
|
335
|
+
`authMessages.en` and `authMessages.pl`, overridable per locale:
|
|
336
|
+
`auth({ messages: { en: { login: { title: "Sign in to Acme" } } } })`. Groups: `fields`, `login`,
|
|
337
|
+
`register`, `changePassword`, `forgotPassword`, `resetPassword`, `resetMail` (the reset mail of
|
|
338
|
+
`mailingResetSender()`; `minutes` holds plural forms), `logout`, and `errors.{auth,security,core}` keyed by the error code
|
|
339
|
+
(`auth.invalid_credentials` → `errors.auth.invalid_credentials`). `getAuthErrorMessage(messages, code)`
|
|
340
|
+
looks one up.
|
|
341
|
+
|
|
342
|
+
## 10. Hooks
|
|
343
|
+
|
|
344
|
+
`onRegistered({ user, consent }, ctx)`: after the user row is inserted, in the same transaction
|
|
345
|
+
(`ctx.db` is the transaction). `consent` is `{ acceptedAt }`, or `null` with
|
|
346
|
+
`requireConsent: false`. A thrown error rolls the registration back and the user sees a generic
|
|
347
|
+
failure. `privacy` (engagement roadmap) stores the consent through it.
|
|
348
|
+
|
|
349
|
+
`passwordReset.send(link, user, details)`: after a reset request is answered, for an existing
|
|
350
|
+
account only (section 4, "Password reset"). `mailingResetSender()` from `@softure-ai/auth/mailing`
|
|
351
|
+
plugs `@softure-ai/mailing` in here.
|
|
352
|
+
|
|
353
|
+
## 11. GDPR
|
|
354
|
+
|
|
355
|
+
The module stores an email, a password hash, session rows, role rows and pending reset rows. It
|
|
356
|
+
contributes to `@softure-ai/privacy` (`privacy` flags on):
|
|
357
|
+
|
|
358
|
+
- **Export** (`exportAuthUserData`): the account (id, email, `createdAt`, `passwordChangedAt`),
|
|
359
|
+
stored roles with their grant dates, sessions (created and expiry dates) and a pending reset link
|
|
360
|
+
(created and expiry dates). Never the password hash or a token hash. A role held through
|
|
361
|
+
`adminEmails` is configuration, so it is not in the export.
|
|
362
|
+
- **Deletion** (`deleteAuthUserData`): the user's sessions, pending reset, roles and then the
|
|
363
|
+
account row, so every session ends with the account. Privacy runs auth after the modules that
|
|
364
|
+
depend on it, and the app's contributors before all modules.
|
|
365
|
+
|
|
366
|
+
`isCurrentPassword(ctx, userId, password)` (`/server`) checks the password again before an action
|
|
367
|
+
that cannot be undone, such as the account deletion; the caller counts the attempt first.
|
|
368
|
+
|
|
369
|
+
Rate limit rows of `security` hold only SHA-256 prefixes of the email and user id
|
|
370
|
+
(`subjectKey`), pruned two windows after they start; they are not exported or deleted.
|
|
371
|
+
|
|
372
|
+
## 12. Limitations / known gaps
|
|
373
|
+
|
|
374
|
+
- Sessions have a fixed lifetime; there is no sliding renewal and no "remember me".
|
|
375
|
+
- A password change keeps the session that made it (and ends every other one); the token itself
|
|
376
|
+
is not rotated. Login and register end the session the browser held before.
|
|
377
|
+
- No email verification, so `adminEmails` trusts whoever registers a listed email first. (A reset
|
|
378
|
+
link goes to the account's email, so its owner can take the account back.)
|
|
379
|
+
- Roles are flat: no hierarchy and no permissions per role; no UI to manage them (the scripts do).
|
|
380
|
+
- The guard checks cookie presence only; the session is verified by `requireUser`.
|
|
381
|
+
- A registration attempt reveals whether an email has an account (`auth.email_taken`); the
|
|
382
|
+
`register` rate limit bounds how fast anyone can ask.
|
|
@@ -0,0 +1,44 @@
|
|
|
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.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
|
+
}
|
|
29
|
+
/** The fields of the auth forms that can carry their own error. */
|
|
30
|
+
export type AuthFormField = "email" | "password" | "currentPassword" | "newPassword" | "consent";
|
|
31
|
+
/**
|
|
32
|
+
* What an auth server action returns to its form (`useActionState`). A successful login or
|
|
33
|
+
* register redirects instead of returning; a password change returns `ok`.
|
|
34
|
+
*/
|
|
35
|
+
export interface AuthFormState {
|
|
36
|
+
readonly status: "idle" | "ok" | "error";
|
|
37
|
+
/** The error to show; when `field` is set it is shown at that field. */
|
|
38
|
+
readonly error?: AuthFormErrorCode;
|
|
39
|
+
readonly field?: AuthFormField;
|
|
40
|
+
/** The submitted email, so a rejected form keeps it (passwords are never sent back). */
|
|
41
|
+
readonly email?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare const INITIAL_AUTH_FORM_STATE: AuthFormState;
|
|
44
|
+
//# 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,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;CACxD;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"}
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AA+DA,MAAM,CAAC,MAAM,uBAAuB,GAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
export declare const MODULE_ID = "auth";
|
|
2
|
+
/** Name of the runtime switch that closes registration. */
|
|
3
|
+
export declare const REGISTRATION_CLOSED_SWITCH = "auth.registration_closed";
|
|
4
|
+
/**
|
|
5
|
+
* The env override of that switch: `true`/`1` or `false`/`0` while auth reads it itself. When the app
|
|
6
|
+
* defines the switch in `@softure-ai/feature-switches`, that module reads the same variable.
|
|
7
|
+
*/
|
|
8
|
+
export declare const REGISTRATION_CLOSED_ENV = "SOFTURE_SWITCH_AUTH_REGISTRATION_CLOSED";
|
|
9
|
+
/**
|
|
10
|
+
* Rate limit buckets auth consumes, with defaults to spread into `security({ buckets })`:
|
|
11
|
+
* `register` and `login` per client address, `login-account` per email, `change-password` per user,
|
|
12
|
+
* `password-reset` (link requests) and `password-reset-confirm` (new passwords) per client address,
|
|
13
|
+
* and `password-reset-account` per email, which bounds the mails one address can receive.
|
|
14
|
+
*/
|
|
15
|
+
export declare const AUTH_RATE_LIMIT_BUCKETS: {
|
|
16
|
+
readonly register: {
|
|
17
|
+
readonly limit: 5;
|
|
18
|
+
readonly windowMinutes: 15;
|
|
19
|
+
};
|
|
20
|
+
readonly login: {
|
|
21
|
+
readonly limit: 50;
|
|
22
|
+
readonly windowMinutes: 15;
|
|
23
|
+
};
|
|
24
|
+
readonly "login-account": {
|
|
25
|
+
readonly limit: 10;
|
|
26
|
+
readonly windowMinutes: 15;
|
|
27
|
+
};
|
|
28
|
+
readonly "change-password": {
|
|
29
|
+
readonly limit: 10;
|
|
30
|
+
readonly windowMinutes: 15;
|
|
31
|
+
};
|
|
32
|
+
readonly "password-reset": {
|
|
33
|
+
readonly limit: 10;
|
|
34
|
+
readonly windowMinutes: 15;
|
|
35
|
+
};
|
|
36
|
+
readonly "password-reset-account": {
|
|
37
|
+
readonly limit: 3;
|
|
38
|
+
readonly windowMinutes: 15;
|
|
39
|
+
};
|
|
40
|
+
readonly "password-reset-confirm": {
|
|
41
|
+
readonly limit: 10;
|
|
42
|
+
readonly windowMinutes: 15;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Enables accounts in `softure.config.ts` (next to `security({ ... })`):
|
|
47
|
+
* `auth({ routes: { afterLogin: "/dashboard" }, password: { minLength: 12 } })`.
|
|
48
|
+
*/
|
|
49
|
+
export declare const auth: import("@softure-ai/core").ModuleFactory<{
|
|
50
|
+
login: string;
|
|
51
|
+
register: string;
|
|
52
|
+
changePassword: string;
|
|
53
|
+
forgotPassword: string;
|
|
54
|
+
resetPassword: string;
|
|
55
|
+
afterLogin: string;
|
|
56
|
+
afterLogout: string;
|
|
57
|
+
}, {
|
|
58
|
+
fields: {
|
|
59
|
+
email: string;
|
|
60
|
+
password: string;
|
|
61
|
+
currentPassword: string;
|
|
62
|
+
newPassword: string;
|
|
63
|
+
newPasswordHint: string;
|
|
64
|
+
consent: string;
|
|
65
|
+
};
|
|
66
|
+
login: {
|
|
67
|
+
title: string;
|
|
68
|
+
lead: string;
|
|
69
|
+
submit: string;
|
|
70
|
+
pending: string;
|
|
71
|
+
noAccount: string;
|
|
72
|
+
registerLink: string;
|
|
73
|
+
forgotPassword: string;
|
|
74
|
+
};
|
|
75
|
+
register: {
|
|
76
|
+
title: string;
|
|
77
|
+
lead: string;
|
|
78
|
+
submit: string;
|
|
79
|
+
pending: string;
|
|
80
|
+
hasAccount: string;
|
|
81
|
+
loginLink: string;
|
|
82
|
+
closedTitle: string;
|
|
83
|
+
closedBody: string;
|
|
84
|
+
};
|
|
85
|
+
changePassword: {
|
|
86
|
+
title: string;
|
|
87
|
+
lead: string;
|
|
88
|
+
submit: string;
|
|
89
|
+
pending: string;
|
|
90
|
+
success: string;
|
|
91
|
+
};
|
|
92
|
+
forgotPassword: {
|
|
93
|
+
title: string;
|
|
94
|
+
lead: string;
|
|
95
|
+
submit: string;
|
|
96
|
+
pending: string;
|
|
97
|
+
sent: string;
|
|
98
|
+
backToLogin: string;
|
|
99
|
+
};
|
|
100
|
+
resetPassword: {
|
|
101
|
+
title: string;
|
|
102
|
+
lead: string;
|
|
103
|
+
submit: string;
|
|
104
|
+
pending: string;
|
|
105
|
+
success: string;
|
|
106
|
+
invalidTitle: string;
|
|
107
|
+
invalidBody: string;
|
|
108
|
+
requestNew: string;
|
|
109
|
+
};
|
|
110
|
+
resetMail: {
|
|
111
|
+
subject: string;
|
|
112
|
+
greeting: string;
|
|
113
|
+
intro: string;
|
|
114
|
+
action: string;
|
|
115
|
+
expiry: string;
|
|
116
|
+
minutes: {
|
|
117
|
+
one: string;
|
|
118
|
+
few: string;
|
|
119
|
+
many: string;
|
|
120
|
+
other: string;
|
|
121
|
+
};
|
|
122
|
+
ignore: string;
|
|
123
|
+
};
|
|
124
|
+
logout: {
|
|
125
|
+
submit: string;
|
|
126
|
+
};
|
|
127
|
+
errors: {
|
|
128
|
+
auth: {
|
|
129
|
+
invalid_credentials: string;
|
|
130
|
+
email_invalid: string;
|
|
131
|
+
email_taken: string;
|
|
132
|
+
password_too_short: string;
|
|
133
|
+
password_too_long: string;
|
|
134
|
+
consent_required: string;
|
|
135
|
+
registration_closed: string;
|
|
136
|
+
current_password_invalid: string;
|
|
137
|
+
unauthenticated: string;
|
|
138
|
+
forbidden: string;
|
|
139
|
+
reset_token_invalid: string;
|
|
140
|
+
password_reset_unavailable: string;
|
|
141
|
+
};
|
|
142
|
+
security: {
|
|
143
|
+
rate_limited: string;
|
|
144
|
+
client_unidentified: string;
|
|
145
|
+
};
|
|
146
|
+
core: {
|
|
147
|
+
database_failed: string;
|
|
148
|
+
unexpected: string;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
}, import("zod").ZodObject<{
|
|
152
|
+
password: import("zod").ZodPrefault<import("zod").ZodObject<{
|
|
153
|
+
minLength: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
154
|
+
scrypt: import("zod").ZodPrefault<import("zod").ZodObject<{
|
|
155
|
+
cost: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
156
|
+
blockSize: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
157
|
+
parallelization: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
158
|
+
}, import("zod/v4/core").$strict>>;
|
|
159
|
+
}, import("zod/v4/core").$strict>>;
|
|
160
|
+
session: import("zod").ZodPrefault<import("zod").ZodObject<{
|
|
161
|
+
ttlDays: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
162
|
+
}, import("zod/v4/core").$strict>>;
|
|
163
|
+
cookie: import("zod").ZodPrefault<import("zod").ZodObject<{
|
|
164
|
+
name: import("zod").ZodDefault<import("zod").ZodString>;
|
|
165
|
+
domain: import("zod").ZodOptional<import("zod").ZodString>;
|
|
166
|
+
secure: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
167
|
+
}, import("zod/v4/core").$strict>>;
|
|
168
|
+
requireConsent: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
169
|
+
registrationClosed: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
170
|
+
roles: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
|
|
171
|
+
adminEmails: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodEmail>>>;
|
|
172
|
+
passwordReset: import("zod").ZodPrefault<import("zod").ZodObject<{
|
|
173
|
+
send: import("zod").ZodOptional<import("zod").ZodCustom<import("./password-reset-sender.js").PasswordResetSender, import("./password-reset-sender.js").PasswordResetSender>>;
|
|
174
|
+
ttlMinutes: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
175
|
+
}, import("zod/v4/core").$strict>>;
|
|
176
|
+
onRegistered: import("zod").ZodOptional<import("zod").ZodCustom<import("./options.js").OnRegisteredHook, import("./options.js").OnRegisteredHook>>;
|
|
177
|
+
rewriteRedirect: import("zod").ZodOptional<import("zod").ZodCustom<import("./options.js").RewriteRedirect, import("./options.js").RewriteRedirect>>;
|
|
178
|
+
}, import("zod/v4/core").$strict>>;
|
|
179
|
+
export { INITIAL_AUTH_FORM_STATE } from "./contract.js";
|
|
180
|
+
export type { AuthErrorCode, AuthFormErrorCode, AuthFormField, AuthFormState, AuthUser, NewSession, RegisteredEvent, SignedIn, } from "./contract.js";
|
|
181
|
+
export { authMessages, getAuthErrorMessage, type AuthMessages } from "./messages/index.js";
|
|
182
|
+
export type { AuthOptions, AuthOptionsInput, OnRegisteredHook, RewriteRedirect, RewriteRedirectContext, ScryptParams } from "./options.js";
|
|
183
|
+
export { consolePasswordResetSender, type PasswordResetDetails, type PasswordResetSender } from "./password-reset-sender.js";
|
|
184
|
+
export { getSessionCookie, type SessionCookie } from "./session-cookie.js";
|
|
185
|
+
export { toSafeNextPath } from "./safe-next-path.js";
|
|
186
|
+
export { ADMIN_ROLE, ROLE_NAME_PATTERN } from "./roles.js";
|
|
187
|
+
export { passwordResets, sessions, userRoles, users } from "./schema.js";
|
|
188
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQ1B,CAAC;AAEX;;;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,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
|