@pithy-sh/auth 0.1.2 → 0.1.3
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/dist/admin/users.d.ts +155 -0
- package/dist/admin/users.d.ts.map +1 -0
- package/dist/admin/users.js +205 -0
- package/dist/audit/actions.d.ts +66 -0
- package/dist/audit/actions.d.ts.map +1 -0
- package/dist/audit/actions.js +66 -0
- package/dist/audit/emit.d.ts +101 -0
- package/dist/audit/emit.d.ts.map +1 -0
- package/dist/audit/emit.js +170 -0
- package/dist/capability.d.ts +60 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +169 -0
- package/dist/client/api.d.ts +299 -0
- package/dist/client/api.d.ts.map +1 -0
- package/dist/client/api.js +385 -0
- package/dist/client/projection.d.ts +51 -0
- package/dist/client/projection.d.ts.map +1 -0
- package/dist/client/projection.js +0 -0
- package/dist/data/betterAuth.d.ts +75 -0
- package/dist/data/betterAuth.d.ts.map +1 -0
- package/dist/data/betterAuth.js +92 -0
- package/dist/data/device.d.ts +36 -0
- package/dist/data/device.d.ts.map +1 -0
- package/dist/data/device.js +33 -0
- package/dist/data/kitFields.d.ts +78 -0
- package/dist/data/kitFields.d.ts.map +1 -0
- package/dist/data/kitFields.js +77 -0
- package/dist/data/rotatedToken.d.ts +20 -0
- package/dist/data/rotatedToken.d.ts.map +1 -0
- package/dist/data/rotatedToken.js +22 -0
- package/dist/data/tables.d.ts +104 -0
- package/dist/data/tables.d.ts.map +1 -0
- package/dist/data/tables.js +30 -0
- package/dist/device/registry.d.ts +54 -0
- package/dist/device/registry.d.ts.map +1 -0
- package/dist/device/registry.js +85 -0
- package/dist/email/send.d.ts +38 -0
- package/dist/email/send.d.ts.map +1 -0
- package/dist/email/send.js +48 -0
- package/dist/http/adminRoutes.d.ts +9 -0
- package/dist/http/adminRoutes.d.ts.map +1 -0
- package/dist/http/adminRoutes.js +274 -0
- package/dist/http/baseUrl.d.ts +41 -0
- package/dist/http/baseUrl.d.ts.map +1 -0
- package/dist/http/baseUrl.js +96 -0
- package/dist/http/csrf.d.ts +18 -0
- package/dist/http/csrf.d.ts.map +1 -0
- package/dist/http/csrf.js +81 -0
- package/dist/http/devLoginRoute.d.ts +42 -0
- package/dist/http/devLoginRoute.d.ts.map +1 -0
- package/dist/http/devLoginRoute.js +112 -0
- package/dist/http/errors.d.ts +24 -0
- package/dist/http/errors.d.ts.map +1 -0
- package/dist/http/errors.js +67 -0
- package/dist/http/guards.d.ts +103 -0
- package/dist/http/guards.d.ts.map +1 -0
- package/dist/http/guards.js +148 -0
- package/dist/http/middleware.d.ts +17 -0
- package/dist/http/middleware.d.ts.map +1 -0
- package/dist/http/middleware.js +47 -0
- package/dist/http/rateLimit.d.ts +17 -0
- package/dist/http/rateLimit.d.ts.map +1 -0
- package/dist/http/rateLimit.js +31 -0
- package/dist/http/resolve.d.ts +9 -0
- package/dist/http/resolve.d.ts.map +1 -0
- package/dist/http/resolve.js +92 -0
- package/dist/http/responses.d.ts +152 -0
- package/dist/http/responses.d.ts.map +1 -0
- package/dist/http/responses.js +121 -0
- package/dist/http/routes.d.ts +34 -0
- package/dist/http/routes.d.ts.map +1 -0
- package/dist/http/routes.js +268 -0
- package/dist/http/schemas.d.ts +66 -0
- package/dist/http/schemas.d.ts.map +1 -0
- package/dist/http/schemas.js +59 -0
- package/dist/http/views.d.ts +53 -0
- package/dist/http/views.d.ts.map +1 -0
- package/dist/http/views.js +86 -0
- package/dist/i18n/errorCopy.d.ts +24 -0
- package/dist/i18n/errorCopy.d.ts.map +1 -0
- package/dist/i18n/errorCopy.es.d.ts +31 -0
- package/dist/i18n/errorCopy.es.d.ts.map +1 -0
- package/dist/i18n/errorCopy.es.js +33 -0
- package/dist/i18n/errorCopy.js +91 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/instance/auth.d.ts +1122 -0
- package/dist/instance/auth.d.ts.map +1 -0
- package/dist/instance/auth.js +176 -0
- package/dist/instance/plugins.d.ts +87 -0
- package/dist/instance/plugins.d.ts.map +1 -0
- package/dist/instance/plugins.js +116 -0
- package/dist/instance/providers.d.ts +117 -0
- package/dist/instance/providers.d.ts.map +1 -0
- package/dist/instance/providers.js +111 -0
- package/dist/instance/secrets.d.ts +163 -0
- package/dist/instance/secrets.d.ts.map +1 -0
- package/dist/instance/secrets.js +169 -0
- package/dist/migrations/0001_init.d.ts +33 -0
- package/dist/migrations/0001_init.d.ts.map +1 -0
- package/dist/migrations/0001_init.js +77 -0
- package/dist/migrations/pluginTables.d.ts +126 -0
- package/dist/migrations/pluginTables.d.ts.map +1 -0
- package/dist/migrations/pluginTables.js +233 -0
- package/dist/seeds/devSession.d.ts +124 -0
- package/dist/seeds/devSession.d.ts.map +1 -0
- package/dist/seeds/devSession.js +211 -0
- package/dist/seeds/example.d.ts +12 -0
- package/dist/seeds/example.d.ts.map +1 -0
- package/dist/seeds/example.js +30 -0
- package/dist/test-utils/liveApp.d.ts +227 -0
- package/dist/test-utils/liveApp.d.ts.map +1 -0
- package/dist/test-utils/liveApp.js +240 -0
- package/dist/token/rotation.d.ts +56 -0
- package/dist/token/rotation.d.ts.map +1 -0
- package/dist/token/rotation.js +68 -0
- package/dist/version.generated.d.ts +5 -0
- package/dist/version.generated.d.ts.map +1 -0
- package/dist/version.generated.js +7 -0
- package/package.json +24 -13
- package/src/version.generated.ts +1 -1
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { authDatabase } from "../data/tables.js";
|
|
2
|
+
import { correlation, emitDenied, emitDeviceRevoked, emitTokenRefresh, emitTokenReuseDetected } from "../audit/emit.js";
|
|
3
|
+
import { deleteDevice, deviceSessionTokens, listDevices } from "../device/registry.js";
|
|
4
|
+
import { getAuthInstance, resolveDb } from "./resolve.js";
|
|
5
|
+
import { requireAuth } from "./middleware.js";
|
|
6
|
+
import { consumeSession, findConsumedToken, pruneConsumedTokens, recordConsumedToken, revokeFamily } from "../token/rotation.js";
|
|
7
|
+
import { RevokeDeviceBody } from "./schemas.js";
|
|
8
|
+
import { registerAuthAdminRoutes } from "./adminRoutes.js";
|
|
9
|
+
import { apiErrorToPithy } from "./errors.js";
|
|
10
|
+
import { UnauthorizedError } from "@pithy-sh/core/src/error/pithyError";
|
|
11
|
+
import { TURNSTILE_LOGIN_ACTION } from "@pithy-sh/turnstile/src/config/config";
|
|
12
|
+
import { zValidator } from "@hono/zod-validator";
|
|
13
|
+
import { requireSameOrigin } from "@pithy-sh/core/src/http/sameOrigin";
|
|
14
|
+
import { validationHook } from "@pithy-sh/core/src/http/validation";
|
|
15
|
+
import { turnstile } from "@pithy-sh/turnstile/src/http/middleware";
|
|
16
|
+
//#region src/http/routes.ts
|
|
17
|
+
function db(c, wiring) {
|
|
18
|
+
return authDatabase(resolveDb(c.env, wiring.config.database));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Register the auth routes onto the backend's Hono app.
|
|
22
|
+
*
|
|
23
|
+
* Order matters: turnstile gates the human-initiated send routes (only when composed), Pithy's own
|
|
24
|
+
* routes are registered before the catch-all so they win, and Better Auth owns everything else under
|
|
25
|
+
* `basePath`. A handler that returns a Response ends the chain, so the specific routes never fall
|
|
26
|
+
* through to the catch-all. (The tier-1 edge rate limiter is contributed as capability *middleware*, so
|
|
27
|
+
* it runs before session resolution — see `capability.ts`.)
|
|
28
|
+
*
|
|
29
|
+
* What each Pithy-owned route accepts, declared on its route line (schemas in `./schemas`):
|
|
30
|
+
*
|
|
31
|
+
* | Route | Verification | Input |
|
|
32
|
+
* | -------------------------- | --------------- | --------------------------- |
|
|
33
|
+
* | `POST /token/rotate` | bearer/session | none — the credential only |
|
|
34
|
+
* | `GET /devices` | bearer/session | none |
|
|
35
|
+
* | `POST /devices/revoke` | bearer/session | json `RevokeDeviceBody` |
|
|
36
|
+
* | `* /admin/*` | control-plane | see `./adminRoutes` |
|
|
37
|
+
*
|
|
38
|
+
* The catch-all takes NO validator, deliberately: `handleBetterAuth` hands Better Auth `c.req.raw`,
|
|
39
|
+
* and reading the body first would consume the stream. Better Auth validates its own endpoints and
|
|
40
|
+
* answers its own refusals; what it rejects reaches a caller in its shape, not ours.
|
|
41
|
+
*
|
|
42
|
+
* **The admin routes must be registered before the catch-all, and it is not a style preference.**
|
|
43
|
+
* `handleBetterAuth` returns a Response, which ends the chain — so a route registered after
|
|
44
|
+
* `app.all(`${base}/*`)` is mounted, is visible in `app.routes`, and never runs. A management call to
|
|
45
|
+
* `/auth/admin/users` would instead reach Better Auth, which knows no such endpoint, and the failure
|
|
46
|
+
* would look like a 404 from the wrong layer. `routeContract.test.ts` proves the ordering with a real
|
|
47
|
+
* request rather than by inspecting the route table, because the route table cannot see this.
|
|
48
|
+
*/
|
|
49
|
+
function createAuthRoutes(wiring) {
|
|
50
|
+
return (app) => {
|
|
51
|
+
const base = wiring.config.basePath;
|
|
52
|
+
const csrf = requireSameOrigin();
|
|
53
|
+
if (wiring.turnstile) {
|
|
54
|
+
const guard = turnstile({
|
|
55
|
+
mode: wiring.turnstile.mode,
|
|
56
|
+
action: TURNSTILE_LOGIN_ACTION
|
|
57
|
+
});
|
|
58
|
+
app.use(`${base}/sign-in/magic-link`, guard);
|
|
59
|
+
app.use(`${base}/email-otp/send-verification-otp`, guard);
|
|
60
|
+
}
|
|
61
|
+
app.post(`${base}/token/rotate`, csrf, (c) => rotateToken(c, wiring));
|
|
62
|
+
app.get(`${base}/devices`, requireAuth(), (c) => listMyDevices(c, wiring));
|
|
63
|
+
app.post(`${base}/devices/revoke`, requireAuth(), csrf, zValidator("json", RevokeDeviceBody, validationHook), (c) => revokeMyDevice(c, wiring, c.req.valid("json")));
|
|
64
|
+
registerAuthAdminRoutes(wiring)(app);
|
|
65
|
+
app.all(`${base}/*`, (c) => handleBetterAuth(c, wiring));
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** The statuses that mean somebody was turned away, rather than that something is broken. */
|
|
69
|
+
const DENIED_STATUSES = /* @__PURE__ */ new Set([
|
|
70
|
+
400,
|
|
71
|
+
401,
|
|
72
|
+
403
|
|
73
|
+
]);
|
|
74
|
+
/**
|
|
75
|
+
* Whether a refused request on this path was an attempt to authenticate.
|
|
76
|
+
*
|
|
77
|
+
* **The audit action is `auth/signin`, so the path has to earn it.** `emitDenied` records
|
|
78
|
+
* `auth/signin outcome=denied actorType=anonymous`, which is the row a brute-force alert counts — and
|
|
79
|
+
* the catch-all under `basePath` carries far more than sign-in. Recording every 4xx there would write
|
|
80
|
+
* a *failed sign-in* for a logged-out tab polling `/update-user` with a stale cookie, and would let an
|
|
81
|
+
* unauthenticated loop against `/list-sessions` bury real credential-stuffing under noise wearing the
|
|
82
|
+
* same anonymous shape.
|
|
83
|
+
*
|
|
84
|
+
* So: the routes where presenting something and being refused *is* the failed attempt — starting a
|
|
85
|
+
* sign-in, completing one at an OAuth callback, and asking for the credential that starts one.
|
|
86
|
+
*/
|
|
87
|
+
function isSignInAttempt(path) {
|
|
88
|
+
return path.includes("/sign-in/") || path.includes("/callback/") || path.includes("/magic-link/") || path.includes("/email-otp/");
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Record a Better Auth refusal on the audit trail.
|
|
92
|
+
*
|
|
93
|
+
* **Read off the Response, because a refusal never arrives as a throw.** `onAPIError: { throw: true }`
|
|
94
|
+
* reads as though an endpoint's `APIError` reaches this module, and it does not: better-auth's
|
|
95
|
+
* `onError` re-raises it (`better-auth/dist/api/index.mjs:193`) directly into better-call's own catch
|
|
96
|
+
* (`better-call@1.4.0`, `dist/router.mjs:83-89`), which renders an `APIError` as a Response and returns
|
|
97
|
+
* it. The throw is swallowed one frame later by the library that asked for it.
|
|
98
|
+
*
|
|
99
|
+
* So the `emitDenied` call this replaces — gated on catching an `APIError` — had never run once. No
|
|
100
|
+
* failed one-time code, no bad magic link, no refused OAuth callback has ever reached
|
|
101
|
+
* `pithy_audit_events`, which is the largest class of security event this capability has (#449).
|
|
102
|
+
*
|
|
103
|
+
* **The body is cloned, never consumed.** The Response is handed back to the caller untouched: Better
|
|
104
|
+
* Auth's own flat shape is a contract adopters read through `createAuthClient`, and the browser client
|
|
105
|
+
* reads it too, so nothing here rewrites it.
|
|
106
|
+
*/
|
|
107
|
+
async function auditRefusal(c, response) {
|
|
108
|
+
if (!DENIED_STATUSES.has(response.status)) return;
|
|
109
|
+
if (!isSignInAttempt(new URL(c.req.raw.url).pathname)) return;
|
|
110
|
+
let body;
|
|
111
|
+
try {
|
|
112
|
+
body = await response.clone().json();
|
|
113
|
+
} catch {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const code = body?.code;
|
|
117
|
+
await emitDenied(c.var.emit, {
|
|
118
|
+
...correlation(c.req.raw.headers),
|
|
119
|
+
detail: typeof code === "string" ? code : void 0
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Delegate to Better Auth's fetch handler, and record what it refused.
|
|
124
|
+
*
|
|
125
|
+
* **The answer is returned exactly as Better Auth wrote it.** Re-homing its flat `{ message, code }`
|
|
126
|
+
* into the kit envelope was tried and taken back out: `packages/auth/README.md` documents
|
|
127
|
+
* `createAuthClient` from `better-auth/client` as a first-class client surface (#271), and
|
|
128
|
+
* `@better-fetch/fetch` builds its error as `{ ...parsedBody, status }` — so rewriting the body would
|
|
129
|
+
* make `error.code` `undefined` for every adopter on the documented path. The wire is Better Auth's
|
|
130
|
+
* contract. `readFailure` in `../client/api` learns to read it instead (#449).
|
|
131
|
+
*
|
|
132
|
+
* The `catch` covers what better-call genuinely hands on: a non-`APIError` throw from an endpoint
|
|
133
|
+
* (`router.mjs:88`), and a throw from a plugin's `onRequest` hook, which runs outside the router's own
|
|
134
|
+
* try. A failure building the instance does **not** come this way — `getAuthInstance` is called before
|
|
135
|
+
* it, and what that throws is already a `PithyError` for `pithyErrorHandler` to render.
|
|
136
|
+
*/
|
|
137
|
+
async function handleBetterAuth(c, wiring) {
|
|
138
|
+
const instance = await getAuthInstance(c, wiring);
|
|
139
|
+
let response;
|
|
140
|
+
try {
|
|
141
|
+
response = await instance.handler(c.req.raw);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
throw apiErrorToPithy(error);
|
|
144
|
+
}
|
|
145
|
+
await auditRefusal(c, response);
|
|
146
|
+
return response;
|
|
147
|
+
}
|
|
148
|
+
/** The raw bearer token presented on the Authorization header, or undefined when none/malformed. */
|
|
149
|
+
function bearerToken(headers) {
|
|
150
|
+
return (headers.get("authorization")?.match(/^Bearer\s+(.+)$/i))?.[1]?.trim() || void 0;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Grace window after a token is consumed during which a replay is treated as a benign concurrent or
|
|
154
|
+
* retried rotation — denied, but WITHOUT revoking the family — rather than compromise. It absorbs a
|
|
155
|
+
* client that fires or retries the same rotation twice (a network race) so a legitimate double-submit
|
|
156
|
+
* never signs the user out everywhere. A replay past the window is a genuine reuse and revokes.
|
|
157
|
+
*/
|
|
158
|
+
const ROTATION_REUSE_GRACE_MS = 3e4;
|
|
159
|
+
/**
|
|
160
|
+
* Rotate the refresh credential. Validates the presented session, mints a fresh one (preserving the
|
|
161
|
+
* device binding and refresh-token family), atomically revokes the old one, and returns a new access
|
|
162
|
+
* token + refresh token. This is the "refresh credential rotates on use" primitive Better Auth does not
|
|
163
|
+
* provide natively.
|
|
164
|
+
*
|
|
165
|
+
* Two hardenings over a naive rotate (#59):
|
|
166
|
+
* - **Reuse detection.** A presented token that no longer resolves to a live session but was previously
|
|
167
|
+
* consumed is a replayed refresh token — the compromise signal for rotated refresh tokens
|
|
168
|
+
* (RFC 6819 §5.2.2.3). The whole family is revoked and the attempt denied. (Covers the bearer refresh
|
|
169
|
+
* flow — the mobile refresh credential; a cookie session presented after rotation already fails closed.)
|
|
170
|
+
* - **Race safety.** The old session is consumed by a conditional delete that exactly one concurrent
|
|
171
|
+
* rotation wins; the loser rolls back its freshly-minted successor. One presented token, one successor.
|
|
172
|
+
*/
|
|
173
|
+
async function rotateToken(c, wiring) {
|
|
174
|
+
const instance = await getAuthInstance(c, wiring);
|
|
175
|
+
const headers = c.req.raw.headers;
|
|
176
|
+
const database = db(c, wiring);
|
|
177
|
+
const ctx = await instance.$context;
|
|
178
|
+
const current = await instance.api.getSession({ headers });
|
|
179
|
+
if (!current) {
|
|
180
|
+
const presented = bearerToken(headers);
|
|
181
|
+
const consumed = presented ? await findConsumedToken(database, presented) : null;
|
|
182
|
+
if (consumed) {
|
|
183
|
+
if (Date.now() - consumed.rotatedAt.getTime() >= ROTATION_REUSE_GRACE_MS) {
|
|
184
|
+
await revokeFamily(database, consumed.familyId, (token) => ctx.internalAdapter.deleteSession(token));
|
|
185
|
+
await emitTokenReuseDetected(c.var.emit, {
|
|
186
|
+
userId: consumed.userId,
|
|
187
|
+
familyId: consumed.familyId,
|
|
188
|
+
...correlation(headers)
|
|
189
|
+
});
|
|
190
|
+
throw new UnauthorizedError({
|
|
191
|
+
message: "This credential has been revoked.",
|
|
192
|
+
action: "Sign in again to obtain a new session."
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
throw new UnauthorizedError({
|
|
196
|
+
message: "Authentication required.",
|
|
197
|
+
action: "Retry with your current session or bearer token."
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
throw new UnauthorizedError({
|
|
201
|
+
message: "Authentication required.",
|
|
202
|
+
action: "Present a valid session or bearer token to rotate."
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
const ip = headers.get("cf-connecting-ip") ?? void 0;
|
|
206
|
+
const userAgent = headers.get("user-agent") ?? void 0;
|
|
207
|
+
const session = current.session;
|
|
208
|
+
const deviceId = session.deviceId ?? void 0;
|
|
209
|
+
const familyId = session.familyId ?? crypto.randomUUID();
|
|
210
|
+
const next = await ctx.internalAdapter.createSession(current.user.id, void 0, {
|
|
211
|
+
ipAddress: ip,
|
|
212
|
+
userAgent,
|
|
213
|
+
familyId,
|
|
214
|
+
...deviceId ? { deviceId } : {}
|
|
215
|
+
});
|
|
216
|
+
const access = await instance.api.getToken({ headers: new Headers({ authorization: `Bearer ${next.token}` }) });
|
|
217
|
+
if (!(await consumeSession(database, session.token)).won) {
|
|
218
|
+
await ctx.internalAdapter.deleteSession(next.token);
|
|
219
|
+
throw new UnauthorizedError({
|
|
220
|
+
message: "Authentication required.",
|
|
221
|
+
action: "Retry with your current session or bearer token."
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
await recordConsumedToken(database, {
|
|
225
|
+
token: session.token,
|
|
226
|
+
familyId,
|
|
227
|
+
userId: current.user.id,
|
|
228
|
+
rotatedAt: /* @__PURE__ */ new Date()
|
|
229
|
+
});
|
|
230
|
+
await emitTokenRefresh(c.var.emit, {
|
|
231
|
+
userId: current.user.id,
|
|
232
|
+
sessionId: next.id,
|
|
233
|
+
ip,
|
|
234
|
+
userAgent
|
|
235
|
+
});
|
|
236
|
+
try {
|
|
237
|
+
await pruneConsumedTokens(database, /* @__PURE__ */ new Date(Date.now() - wiring.config.sessionExpiresIn * 1e3));
|
|
238
|
+
} catch {}
|
|
239
|
+
return c.json({
|
|
240
|
+
accessToken: access.token,
|
|
241
|
+
refreshToken: next.token,
|
|
242
|
+
expiresAt: next.expiresAt
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/** List the authenticated user's registered devices. */
|
|
246
|
+
async function listMyDevices(c, wiring) {
|
|
247
|
+
const userId = c.var.auth?.userId;
|
|
248
|
+
if (!userId) throw new UnauthorizedError({ message: "Authentication required." });
|
|
249
|
+
return c.json({ devices: await listDevices(db(c, wiring), userId) });
|
|
250
|
+
}
|
|
251
|
+
/** Revoke one of the authenticated user's devices: sign out its sessions, then drop the device row. */
|
|
252
|
+
async function revokeMyDevice(c, wiring, body) {
|
|
253
|
+
const userId = c.var.auth?.userId;
|
|
254
|
+
if (!userId) throw new UnauthorizedError({ message: "Authentication required." });
|
|
255
|
+
const deviceId = body.deviceId;
|
|
256
|
+
const database = db(c, wiring);
|
|
257
|
+
const tokens = await deviceSessionTokens(database, userId, deviceId);
|
|
258
|
+
const ctx = await (await getAuthInstance(c, wiring)).$context;
|
|
259
|
+
for (const token of tokens) await ctx.internalAdapter.deleteSession(token);
|
|
260
|
+
await deleteDevice(database, userId, deviceId);
|
|
261
|
+
await emitDeviceRevoked(c.var.emit, {
|
|
262
|
+
userId,
|
|
263
|
+
...correlation(c.req.raw.headers)
|
|
264
|
+
});
|
|
265
|
+
return c.json({ revoked: tokens.length });
|
|
266
|
+
}
|
|
267
|
+
//#endregion
|
|
268
|
+
export { createAuthRoutes };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The request schemas for the auth routes Pithy owns. Validation happens at the HTTP boundary
|
|
4
|
+
* (CLAUDE.md §Zod), declared on the route line with `zValidator(target, Schema, validationHook)` — so
|
|
5
|
+
* reading `routes.ts` and `adminRoutes.ts` tells you what each route accepts without opening a handler.
|
|
6
|
+
*
|
|
7
|
+
* Only Pithy's own routes appear here. Everything under `basePath` that Better Auth owns validates
|
|
8
|
+
* itself, behind a catch-all that must hand it an unread request body.
|
|
9
|
+
*
|
|
10
|
+
* Every schema below the first is a bound on something a **management client** chose. Verified is not
|
|
11
|
+
* the same as trusted: a control-plane credential proves who is calling, not that their pagination is
|
|
12
|
+
* sane, and a client with a bug asks for a million user rows exactly as easily as a hostile one does.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The body of `POST /devices/revoke` and of the admin `POST /admin/users/:userId/devices/revoke`.
|
|
16
|
+
* `deviceId` is client-minted (it arrives as the `x-pithy-device-id` header at sign-in), so it is
|
|
17
|
+
* bounded rather than shape-checked: a well-formed id that matches no row must still reach the handler,
|
|
18
|
+
* which answers `{ revoked: 0 }`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const RevokeDeviceBody: z.ZodObject<{
|
|
21
|
+
deviceId: z.ZodString;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
export type RevokeDeviceBody = z.output<typeof RevokeDeviceBody>;
|
|
24
|
+
/**
|
|
25
|
+
* The user id in the path of every single-user admin route.
|
|
26
|
+
*
|
|
27
|
+
* Bounded rather than `.uuid()`: Better Auth's id generator is configurable and its default is not a
|
|
28
|
+
* UUID, so a UUID shape here would 404 — as a 400 — every user in a project that changed it. The schema
|
|
29
|
+
* constrains the string; the handler still does the lookup and raises its own `core/not_found`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const UserIdParam: z.ZodObject<{
|
|
32
|
+
userId: z.ZodString;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
export type UserIdParam = z.output<typeof UserIdParam>;
|
|
35
|
+
/** The user listing query. */
|
|
36
|
+
export declare const ListUsersQuery: z.ZodObject<{
|
|
37
|
+
search: z.ZodOptional<z.ZodString>;
|
|
38
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
39
|
+
limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
export type ListUsersQuery = z.output<typeof ListUsersQuery>;
|
|
42
|
+
/** The device-registry listing query. */
|
|
43
|
+
export declare const ListDevicesQuery: z.ZodObject<{
|
|
44
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
45
|
+
platform: z.ZodOptional<z.ZodEnum<{
|
|
46
|
+
android: "android";
|
|
47
|
+
ios: "ios";
|
|
48
|
+
web: "web";
|
|
49
|
+
}>>;
|
|
50
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
51
|
+
limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
export type ListDevicesQuery = z.output<typeof ListDevicesQuery>;
|
|
54
|
+
/**
|
|
55
|
+
* The body of `POST /admin/sessions/revoke`.
|
|
56
|
+
*
|
|
57
|
+
* A session **id**, never a session token. The token is the live credential — a management client that
|
|
58
|
+
* could name one would be holding the thing it is revoking, and a route that accepted one would be an
|
|
59
|
+
* oracle for whether a captured token is still valid. The id is the row's public handle, which is what
|
|
60
|
+
* the read routes project.
|
|
61
|
+
*/
|
|
62
|
+
export declare const RevokeSessionBody: z.ZodObject<{
|
|
63
|
+
sessionId: z.ZodString;
|
|
64
|
+
}, z.core.$strip>;
|
|
65
|
+
export type RevokeSessionBody = z.output<typeof RevokeSessionBody>;
|
|
66
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/http/schemas.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;;GAWG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;;iBAQ2E,CAAC;AACzG,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEjE;;;;;;GAMG;AACH,eAAO,MAAM,WAAW;;iBAIoD,CAAC;AAC7E,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAkBvD,8BAA8B;AAC9B,eAAO,MAAM,cAAc;;;;iBAawE,CAAC;AACpG,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAE7D,yCAAyC;AACzC,eAAO,MAAM,gBAAgB;;;;;;;;;iBAYwE,CAAC;AACtG,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEjE;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;;iBAQqC,CAAC;AACpE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DevicePlatform } from "../data/device.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { MAX_PAGE_SIZE } from "@pithy-sh/core/src/data/cursor";
|
|
4
|
+
//#region src/http/schemas.ts
|
|
5
|
+
/**
|
|
6
|
+
* The request schemas for the auth routes Pithy owns. Validation happens at the HTTP boundary
|
|
7
|
+
* (CLAUDE.md §Zod), declared on the route line with `zValidator(target, Schema, validationHook)` — so
|
|
8
|
+
* reading `routes.ts` and `adminRoutes.ts` tells you what each route accepts without opening a handler.
|
|
9
|
+
*
|
|
10
|
+
* Only Pithy's own routes appear here. Everything under `basePath` that Better Auth owns validates
|
|
11
|
+
* itself, behind a catch-all that must hand it an unread request body.
|
|
12
|
+
*
|
|
13
|
+
* Every schema below the first is a bound on something a **management client** chose. Verified is not
|
|
14
|
+
* the same as trusted: a control-plane credential proves who is calling, not that their pagination is
|
|
15
|
+
* sane, and a client with a bug asks for a million user rows exactly as easily as a hostile one does.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The body of `POST /devices/revoke` and of the admin `POST /admin/users/:userId/devices/revoke`.
|
|
19
|
+
* `deviceId` is client-minted (it arrives as the `x-pithy-device-id` header at sign-in), so it is
|
|
20
|
+
* bounded rather than shape-checked: a well-formed id that matches no row must still reach the handler,
|
|
21
|
+
* which answers `{ revoked: 0 }`.
|
|
22
|
+
*/
|
|
23
|
+
const RevokeDeviceBody = z.object({ deviceId: z.string().min(1).max(256).describe("The id of the device to revoke — the client-generated id it registered at sign-in.") }).describe("The body identifying which device to revoke — the caller's own, or an admin-named user's.");
|
|
24
|
+
/**
|
|
25
|
+
* The user id in the path of every single-user admin route.
|
|
26
|
+
*
|
|
27
|
+
* Bounded rather than `.uuid()`: Better Auth's id generator is configurable and its default is not a
|
|
28
|
+
* UUID, so a UUID shape here would 404 — as a 400 — every user in a project that changed it. The schema
|
|
29
|
+
* constrains the string; the handler still does the lookup and raises its own `core/not_found`.
|
|
30
|
+
*/
|
|
31
|
+
const UserIdParam = z.object({ userId: z.string().min(1).max(255).describe("The user's id, as `pithy_auth_users.id` stores it.") }).describe("The path parameters of every admin route that names one user.");
|
|
32
|
+
/** How many rows a paged admin listing returns, when the caller names a number. */
|
|
33
|
+
const PageLimit = z.coerce.number().int().min(1).max(MAX_PAGE_SIZE).optional().describe("How many rows to return. Bounded, because a verified client can still have a bug.");
|
|
34
|
+
/** Where a paged admin listing resumes. */
|
|
35
|
+
const PageCursorParam = z.string().max(512).optional().describe("Where to resume, from the previous page's `nextCursor`. Opaque; a malformed one is a first page.");
|
|
36
|
+
/** The user listing query. */
|
|
37
|
+
const ListUsersQuery = z.object({
|
|
38
|
+
search: z.string().min(1).max(200).optional().describe("Free text matched against email and display name. `%` and `_` are escaped rather than treated as wildcards, so an address containing an underscore matches itself and nothing else."),
|
|
39
|
+
cursor: PageCursorParam,
|
|
40
|
+
limit: PageLimit
|
|
41
|
+
}).describe("The user listing query: what to search for, how many to return, and where to resume.");
|
|
42
|
+
/** The device-registry listing query. */
|
|
43
|
+
const ListDevicesQuery = z.object({
|
|
44
|
+
userId: z.string().min(1).max(255).optional().describe("Narrow to one user's devices. Absent walks the whole fleet, most-recently-seen first."),
|
|
45
|
+
platform: DevicePlatform.optional().describe("Narrow to one platform."),
|
|
46
|
+
cursor: PageCursorParam,
|
|
47
|
+
limit: PageLimit
|
|
48
|
+
}).describe("The device-registry query: what to filter by, how many to return, and where to resume.");
|
|
49
|
+
/**
|
|
50
|
+
* The body of `POST /admin/sessions/revoke`.
|
|
51
|
+
*
|
|
52
|
+
* A session **id**, never a session token. The token is the live credential — a management client that
|
|
53
|
+
* could name one would be holding the thing it is revoking, and a route that accepted one would be an
|
|
54
|
+
* oracle for whether a captured token is still valid. The id is the row's public handle, which is what
|
|
55
|
+
* the read routes project.
|
|
56
|
+
*/
|
|
57
|
+
const RevokeSessionBody = z.object({ sessionId: z.string().min(1).max(255).describe("The session's id, as the admin read routes report it. Not the session token.") }).describe("The body identifying which single session to revoke.");
|
|
58
|
+
//#endregion
|
|
59
|
+
export { ListDevicesQuery, ListUsersQuery, RevokeDeviceBody, RevokeSessionBody, UserIdParam };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Session, User } from "../data/betterAuth";
|
|
2
|
+
import type { Device } from "../data/device";
|
|
3
|
+
import type { AdminDeviceView, AdminSessionView, AdminUserView } from "./responses";
|
|
4
|
+
/**
|
|
5
|
+
* The admin projections — what a management client is shown of a user, a session, and a device.
|
|
6
|
+
*
|
|
7
|
+
* **No handler returns a row.** Each function below states what leaves the Worker, and each return
|
|
8
|
+
* type is `z.output` of the matching object in `responses.ts`, so the shape a client validates
|
|
9
|
+
* against and the shape this produces are one declaration. Adding a field to one and not the other
|
|
10
|
+
* does not compile.
|
|
11
|
+
*
|
|
12
|
+
* Separated from `adminRoutes.ts` so they can be exercised without a request, a scope, or a
|
|
13
|
+
* credential: `responses.test.ts` runs each against a fully populated row and compares the result
|
|
14
|
+
* with its schema. A leak here is a leak in every pane, and it should not need a Workers pool to
|
|
15
|
+
* catch.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The user projection.
|
|
19
|
+
*
|
|
20
|
+
* Email and display name are personal data and they are here on purpose: identifying the right person
|
|
21
|
+
* is the entire job of a support pane, and `auth:users:read` is precisely the grant an adopter makes
|
|
22
|
+
* when they accept that. Nothing else on `pithy_auth_users` is withheld because nothing else on it is
|
|
23
|
+
* sensitive — the table holds no credential at all, which is what passwordless-only buys.
|
|
24
|
+
*
|
|
25
|
+
* `locale` is projected for the same reason: a support pane answering "why is this person getting
|
|
26
|
+
* English emails" needs to see whether they ever chose, and null — never chosen — is the answer half
|
|
27
|
+
* the time. It is a preference, not a credential.
|
|
28
|
+
*/
|
|
29
|
+
export declare function userView(user: User): AdminUserView;
|
|
30
|
+
/**
|
|
31
|
+
* The session projection — **without the token**.
|
|
32
|
+
*
|
|
33
|
+
* The token *is* the credential: a bearer of it is the user, everywhere, until it expires. Projecting
|
|
34
|
+
* it would turn a read scope into silent impersonation and would leave no trace distinguishable from
|
|
35
|
+
* the person's own activity, which is exactly the capability this surface refuses to offer. The `id` is
|
|
36
|
+
* the handle instead, and it is what `POST /admin/sessions/revoke` accepts.
|
|
37
|
+
*
|
|
38
|
+
* `familyId` is dropped too — it is internal rotation bookkeeping, and a pane that rendered it would
|
|
39
|
+
* invite somebody to act on a correlation the model does not promise to keep stable.
|
|
40
|
+
*
|
|
41
|
+
* The IP and user-agent stay: "where is this person signed in from" is the question the pane exists to
|
|
42
|
+
* answer, and it is the one that catches a stolen session.
|
|
43
|
+
*/
|
|
44
|
+
export declare function sessionView(session: Session): AdminSessionView;
|
|
45
|
+
/**
|
|
46
|
+
* The device projection — **without the push token**.
|
|
47
|
+
*
|
|
48
|
+
* An APNs/FCM token is the capability to put a notification on somebody's lock screen. It is a
|
|
49
|
+
* credential, it is useless to a dashboard, and a management client that held one could message an
|
|
50
|
+
* adopter's users under the adopter's own app identity. It never leaves the Worker.
|
|
51
|
+
*/
|
|
52
|
+
export declare function deviceView(device: Device): AdminDeviceView;
|
|
53
|
+
//# sourceMappingURL=views.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"views.d.ts","sourceRoot":"","sources":["../../src/http/views.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEpF;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,CAWlD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAU9D;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,CAa1D"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//#region src/http/views.ts
|
|
2
|
+
/**
|
|
3
|
+
* The admin projections — what a management client is shown of a user, a session, and a device.
|
|
4
|
+
*
|
|
5
|
+
* **No handler returns a row.** Each function below states what leaves the Worker, and each return
|
|
6
|
+
* type is `z.output` of the matching object in `responses.ts`, so the shape a client validates
|
|
7
|
+
* against and the shape this produces are one declaration. Adding a field to one and not the other
|
|
8
|
+
* does not compile.
|
|
9
|
+
*
|
|
10
|
+
* Separated from `adminRoutes.ts` so they can be exercised without a request, a scope, or a
|
|
11
|
+
* credential: `responses.test.ts` runs each against a fully populated row and compares the result
|
|
12
|
+
* with its schema. A leak here is a leak in every pane, and it should not need a Workers pool to
|
|
13
|
+
* catch.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* The user projection.
|
|
17
|
+
*
|
|
18
|
+
* Email and display name are personal data and they are here on purpose: identifying the right person
|
|
19
|
+
* is the entire job of a support pane, and `auth:users:read` is precisely the grant an adopter makes
|
|
20
|
+
* when they accept that. Nothing else on `pithy_auth_users` is withheld because nothing else on it is
|
|
21
|
+
* sensitive — the table holds no credential at all, which is what passwordless-only buys.
|
|
22
|
+
*
|
|
23
|
+
* `locale` is projected for the same reason: a support pane answering "why is this person getting
|
|
24
|
+
* English emails" needs to see whether they ever chose, and null — never chosen — is the answer half
|
|
25
|
+
* the time. It is a preference, not a credential.
|
|
26
|
+
*/
|
|
27
|
+
function userView(user) {
|
|
28
|
+
return {
|
|
29
|
+
id: user.id,
|
|
30
|
+
email: user.email,
|
|
31
|
+
name: user.name,
|
|
32
|
+
emailVerified: user.emailVerified,
|
|
33
|
+
image: user.image,
|
|
34
|
+
locale: user.locale,
|
|
35
|
+
createdAt: user.createdAt.toISOString(),
|
|
36
|
+
updatedAt: user.updatedAt.toISOString()
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The session projection — **without the token**.
|
|
41
|
+
*
|
|
42
|
+
* The token *is* the credential: a bearer of it is the user, everywhere, until it expires. Projecting
|
|
43
|
+
* it would turn a read scope into silent impersonation and would leave no trace distinguishable from
|
|
44
|
+
* the person's own activity, which is exactly the capability this surface refuses to offer. The `id` is
|
|
45
|
+
* the handle instead, and it is what `POST /admin/sessions/revoke` accepts.
|
|
46
|
+
*
|
|
47
|
+
* `familyId` is dropped too — it is internal rotation bookkeeping, and a pane that rendered it would
|
|
48
|
+
* invite somebody to act on a correlation the model does not promise to keep stable.
|
|
49
|
+
*
|
|
50
|
+
* The IP and user-agent stay: "where is this person signed in from" is the question the pane exists to
|
|
51
|
+
* answer, and it is the one that catches a stolen session.
|
|
52
|
+
*/
|
|
53
|
+
function sessionView(session) {
|
|
54
|
+
return {
|
|
55
|
+
id: session.id,
|
|
56
|
+
deviceId: session.deviceId,
|
|
57
|
+
ipAddress: session.ipAddress,
|
|
58
|
+
userAgent: session.userAgent,
|
|
59
|
+
createdAt: session.createdAt.toISOString(),
|
|
60
|
+
updatedAt: session.updatedAt.toISOString(),
|
|
61
|
+
expiresAt: session.expiresAt.toISOString()
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The device projection — **without the push token**.
|
|
66
|
+
*
|
|
67
|
+
* An APNs/FCM token is the capability to put a notification on somebody's lock screen. It is a
|
|
68
|
+
* credential, it is useless to a dashboard, and a management client that held one could message an
|
|
69
|
+
* adopter's users under the adopter's own app identity. It never leaves the Worker.
|
|
70
|
+
*/
|
|
71
|
+
function deviceView(device) {
|
|
72
|
+
return {
|
|
73
|
+
id: device.id,
|
|
74
|
+
userId: device.userId,
|
|
75
|
+
platform: device.platform,
|
|
76
|
+
name: device.name,
|
|
77
|
+
model: device.model,
|
|
78
|
+
osVersion: device.osVersion,
|
|
79
|
+
appVersion: device.appVersion,
|
|
80
|
+
lastIp: device.lastIp,
|
|
81
|
+
lastSeenAt: device.lastSeenAt.toISOString(),
|
|
82
|
+
createdAt: device.createdAt.toISOString()
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
export { deviceView, sessionView, userView };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BetterAuthPlugin } from "better-auth";
|
|
2
|
+
/**
|
|
3
|
+
* Codes that stay English on purpose, and why.
|
|
4
|
+
*
|
|
5
|
+
* **A declared list rather than a silent remainder.** The gate in `./errorCopy.test.ts` requires every
|
|
6
|
+
* code the composed plugin set can raise to be either translated or named here, so a code Better Auth
|
|
7
|
+
* adds in a later release fails the build instead of quietly reaching somebody in English. That is the
|
|
8
|
+
* same shape the migration-order table uses, and for the same reason: the property is only true as a
|
|
9
|
+
* set.
|
|
10
|
+
*
|
|
11
|
+
* Every entry is a fault an **adopter** caused in their own configuration or their own request, not
|
|
12
|
+
* anything a reader can act on. Translating those makes them harder to search for and no easier to fix.
|
|
13
|
+
*/
|
|
14
|
+
export declare const ENGLISH_ON_PURPOSE: Record<string, string>;
|
|
15
|
+
/** Every error code the given plugin set can raise, plus Better Auth's own base vocabulary. */
|
|
16
|
+
export declare function composedErrorCodes(plugins: readonly BetterAuthPlugin[]): string[];
|
|
17
|
+
/**
|
|
18
|
+
* The dictionary the plugin is configured with: what it ships, with this kit's own words over the top.
|
|
19
|
+
*
|
|
20
|
+
* `en` is included and is the plugin's own, so a reader whose negotiated locale is English gets exactly
|
|
21
|
+
* the sentences Better Auth already wrote — this changes nothing for a project that serves one language.
|
|
22
|
+
*/
|
|
23
|
+
export declare function authErrorTranslations(): Record<string, Record<string, string>>;
|
|
24
|
+
//# sourceMappingURL=errorCopy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorCopy.d.ts","sourceRoot":"","sources":["../../src/i18n/errorCopy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAsCpD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAerD,CAAC;AAEF,+FAA+F;AAC/F,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,MAAM,EAAE,CAOjF;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAW9E"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What this kit says in Spanish that `@better-auth/i18n` does not (#452).
|
|
3
|
+
*
|
|
4
|
+
* **Only the gaps, and only the ones a reader meets.** The plugin ships 22 languages of its own, and
|
|
5
|
+
* they are maintained upstream — copying them here would fork every one of them on the day it landed.
|
|
6
|
+
* This layers over its `es`, which covers 34 of the 52 codes the kit's composed plugin set can raise.
|
|
7
|
+
*
|
|
8
|
+
* The three that matter most were among the missing: `INVALID_OTP`, `OTP_EXPIRED` and
|
|
9
|
+
* `TOO_MANY_ATTEMPTS` are the whole of `emailOTP`'s vocabulary, which is to say the whole of what a
|
|
10
|
+
* person meets when a passwordless sign-in goes wrong. A reader who mistyped a code was reading English
|
|
11
|
+
* on an otherwise Spanish screen.
|
|
12
|
+
*
|
|
13
|
+
* The rest of the gap is misconfiguration an adopter causes rather than anything a reader can act on,
|
|
14
|
+
* and it stays English deliberately — see `ENGLISH_ON_PURPOSE` in `./errorCopy`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const AUTH_ERRORS_ES: {
|
|
17
|
+
/** A one-time code that is not the one. The commonest refusal there is. */
|
|
18
|
+
readonly INVALID_OTP: "El código no es válido.";
|
|
19
|
+
/** The code was right once. Codes are short-lived on purpose. */
|
|
20
|
+
readonly OTP_EXPIRED: "El código ha caducado. Pide uno nuevo.";
|
|
21
|
+
/** Rate limiting on the verification attempt, not on the request for a code. */
|
|
22
|
+
readonly TOO_MANY_ATTEMPTS: "Demasiados intentos. Espera un momento y vuelve a intentarlo.";
|
|
23
|
+
/**
|
|
24
|
+
* The sign-in was reached by a cross-site navigation and refused.
|
|
25
|
+
*
|
|
26
|
+
* A person can meet this without doing anything wrong — an embedded browser, a link opened from
|
|
27
|
+
* another site — so it says what to do rather than naming the mechanism.
|
|
28
|
+
*/
|
|
29
|
+
readonly CROSS_SITE_NAVIGATION_LOGIN_BLOCKED: "Por seguridad, abre el enlace directamente en tu navegador.";
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=errorCopy.es.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorCopy.es.d.ts","sourceRoot":"","sources":["../../src/i18n/errorCopy.es.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc;IACzB,2EAA2E;0BAC9D,yBAAyB;IACtC,iEAAiE;0BACpD,wCAAwC;IACrD,gFAAgF;gCAC7D,+DAA+D;IAClF;;;;;OAKG;kDACkC,6DAA6D;CACzD,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/i18n/errorCopy.es.ts
|
|
2
|
+
/**
|
|
3
|
+
* What this kit says in Spanish that `@better-auth/i18n` does not (#452).
|
|
4
|
+
*
|
|
5
|
+
* **Only the gaps, and only the ones a reader meets.** The plugin ships 22 languages of its own, and
|
|
6
|
+
* they are maintained upstream — copying them here would fork every one of them on the day it landed.
|
|
7
|
+
* This layers over its `es`, which covers 34 of the 52 codes the kit's composed plugin set can raise.
|
|
8
|
+
*
|
|
9
|
+
* The three that matter most were among the missing: `INVALID_OTP`, `OTP_EXPIRED` and
|
|
10
|
+
* `TOO_MANY_ATTEMPTS` are the whole of `emailOTP`'s vocabulary, which is to say the whole of what a
|
|
11
|
+
* person meets when a passwordless sign-in goes wrong. A reader who mistyped a code was reading English
|
|
12
|
+
* on an otherwise Spanish screen.
|
|
13
|
+
*
|
|
14
|
+
* The rest of the gap is misconfiguration an adopter causes rather than anything a reader can act on,
|
|
15
|
+
* and it stays English deliberately — see `ENGLISH_ON_PURPOSE` in `./errorCopy`.
|
|
16
|
+
*/
|
|
17
|
+
const AUTH_ERRORS_ES = {
|
|
18
|
+
/** A one-time code that is not the one. The commonest refusal there is. */
|
|
19
|
+
INVALID_OTP: "El código no es válido.",
|
|
20
|
+
/** The code was right once. Codes are short-lived on purpose. */
|
|
21
|
+
OTP_EXPIRED: "El código ha caducado. Pide uno nuevo.",
|
|
22
|
+
/** Rate limiting on the verification attempt, not on the request for a code. */
|
|
23
|
+
TOO_MANY_ATTEMPTS: "Demasiados intentos. Espera un momento y vuelve a intentarlo.",
|
|
24
|
+
/**
|
|
25
|
+
* The sign-in was reached by a cross-site navigation and refused.
|
|
26
|
+
*
|
|
27
|
+
* A person can meet this without doing anything wrong — an embedded browser, a link opened from
|
|
28
|
+
* another site — so it says what to do rather than naming the mechanism.
|
|
29
|
+
*/
|
|
30
|
+
CROSS_SITE_NAVIGATION_LOGIN_BLOCKED: "Por seguridad, abre el enlace directamente en tu navegador."
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { AUTH_ERRORS_ES };
|