@pithy-sh/auth 0.1.1 → 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,233 @@
|
|
|
1
|
+
import { authTables } from "../data/tables.js";
|
|
2
|
+
import { KIT_SESSION_FIELDS, KIT_USER_FIELDS } from "../data/kitFields.js";
|
|
3
|
+
import { kitPlugins } from "../instance/plugins.js";
|
|
4
|
+
import { ValidationError } from "@pithy-sh/core/src/error/pithyError";
|
|
5
|
+
import { getSchema } from "better-auth/db";
|
|
6
|
+
//#region src/migrations/pluginTables.ts
|
|
7
|
+
/**
|
|
8
|
+
* Deriving an adopter's Better Auth plugin tables, and creating them through `pithy migrate`.
|
|
9
|
+
*
|
|
10
|
+
* The kit's migration model is per-capability sets composed by `pithy migrate`, and until now there was
|
|
11
|
+
* no path for tables an **adopter** introduced through a capability's plugin. This is that path, and it
|
|
12
|
+
* works because the plugin list is in `pithy.config.ts` — the same file the CLI already imports to
|
|
13
|
+
* collect capabilities. The auth capability reads its own config, asks Better Auth what schema those
|
|
14
|
+
* plugins imply, and contributes one ordinary Kysely migration per plugin. Nothing new was added to the
|
|
15
|
+
* migration model; the capability simply declares more of it.
|
|
16
|
+
*
|
|
17
|
+
* **The diff is against a baseline, not against nothing.** `getSchema` answers with the *whole* schema
|
|
18
|
+
* for a set of options, so the same call is made twice — once with only the kit's own plugins, once
|
|
19
|
+
* with the kit's own plus one adopter plugin — and the difference is what that plugin brought. That is
|
|
20
|
+
* what keeps the derived migration from re-creating `pithy_auth_users` on every project.
|
|
21
|
+
*
|
|
22
|
+
* **A plugin brings two kinds of change and both matter.** `organization` adds three tables *and* an
|
|
23
|
+
* `activeOrganizationId` column to the session table the kit already owns; a create-table-only reading
|
|
24
|
+
* ships a schema where `setActive` fails on the first call. Both halves are derived here.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* The Better Auth options that shape the schema, and only those. Model names, the session's extra
|
|
28
|
+
* fields, and the rate-limit table are all read by `getSchema`, so the baseline it computes has to
|
|
29
|
+
* carry the same ones `makeAuth` passes or the diff would report the kit's own tables as new.
|
|
30
|
+
*
|
|
31
|
+
* Kept beside `makeAuth` rather than inside it because the migration is built at `auth(config)` time,
|
|
32
|
+
* where the request-scoped deps (database, secret, base URL) do not exist yet — and none of them
|
|
33
|
+
* changes a column.
|
|
34
|
+
*/
|
|
35
|
+
function authSchemaOptions(plugins) {
|
|
36
|
+
return {
|
|
37
|
+
user: {
|
|
38
|
+
modelName: "pithyAuthUsers",
|
|
39
|
+
additionalFields: KIT_USER_FIELDS
|
|
40
|
+
},
|
|
41
|
+
session: {
|
|
42
|
+
modelName: "pithyAuthSessions",
|
|
43
|
+
additionalFields: KIT_SESSION_FIELDS
|
|
44
|
+
},
|
|
45
|
+
account: { modelName: "pithyAuthAccounts" },
|
|
46
|
+
verification: { modelName: "pithyAuthVerifications" },
|
|
47
|
+
rateLimit: {
|
|
48
|
+
enabled: true,
|
|
49
|
+
storage: "database",
|
|
50
|
+
modelName: "pithyAuthRateLimit"
|
|
51
|
+
},
|
|
52
|
+
plugins: [...kitPlugins({
|
|
53
|
+
verificationExpiresIn: 300,
|
|
54
|
+
otpLength: 6,
|
|
55
|
+
disableSignUp: false,
|
|
56
|
+
sendEmail: async () => void 0
|
|
57
|
+
}), ...plugins]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Map a Better Auth field type to SQLite storage.
|
|
62
|
+
*
|
|
63
|
+
* `date` is **text**, not SQLite's `date` affinity: Better Auth stores ISO-8601 strings on SQLite, ISO
|
|
64
|
+
* sorts chronologically, and `0001_init` already declares every Better-Auth date column that way. A
|
|
65
|
+
* list type (`string[]`, `number[]`) and a literal-union type are both JSON/text on SQLite, which is
|
|
66
|
+
* what Better Auth's own generator does. Anything else is a `boolean`/`number`/`string` — the two
|
|
67
|
+
* numeric-ish ones are `integer`, everything else `text`.
|
|
68
|
+
*/
|
|
69
|
+
function columnType(type) {
|
|
70
|
+
return type === "boolean" || type === "number" ? "integer" : "text";
|
|
71
|
+
}
|
|
72
|
+
/** The kit's own tables — the six Better Auth manages plus `devices` and `rotated_tokens`. */
|
|
73
|
+
const KIT_TABLE_NAMES = Object.keys(authTables);
|
|
74
|
+
/**
|
|
75
|
+
* What one plugin adds to the auth schema, as a plan a migration can be built from.
|
|
76
|
+
*
|
|
77
|
+
* **Every added column is nullable, deliberately.** SQLite refuses `ALTER TABLE … ADD COLUMN … NOT NULL`
|
|
78
|
+
* without a constant default, and the table it is being added to is a live one that already has rows —
|
|
79
|
+
* so a plugin's `required` on a *new* column of an *existing* table cannot be honored by any migration,
|
|
80
|
+
* whatever it claims. Better Auth writes the value on every insert it makes, so the constraint is
|
|
81
|
+
* enforced where the plugin enforces it; the column simply does not also declare it. A column of a table
|
|
82
|
+
* the plugin creates itself is `NOT NULL` normally — there are no rows to contradict it.
|
|
83
|
+
*/
|
|
84
|
+
function pluginSchemaDelta(plugin) {
|
|
85
|
+
const baseline = getSchema(authSchemaOptions([]));
|
|
86
|
+
const extended = getSchema(authSchemaOptions([plugin]));
|
|
87
|
+
const tables = [];
|
|
88
|
+
const columns = [];
|
|
89
|
+
for (const [model, spec] of Object.entries(extended)) {
|
|
90
|
+
const before = baseline[model];
|
|
91
|
+
const fields = Object.entries(spec.fields);
|
|
92
|
+
if (!before) {
|
|
93
|
+
tables.push({
|
|
94
|
+
name: model,
|
|
95
|
+
columns: [{
|
|
96
|
+
name: "id",
|
|
97
|
+
type: "text",
|
|
98
|
+
notNull: true,
|
|
99
|
+
primaryKey: true,
|
|
100
|
+
unique: false,
|
|
101
|
+
index: false
|
|
102
|
+
}, ...fields.map(([name, field]) => ({
|
|
103
|
+
name,
|
|
104
|
+
type: columnType(field.type),
|
|
105
|
+
notNull: field.required !== false,
|
|
106
|
+
primaryKey: false,
|
|
107
|
+
unique: field.unique === true,
|
|
108
|
+
index: field.index === true
|
|
109
|
+
}))]
|
|
110
|
+
});
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
for (const [name, field] of fields) {
|
|
114
|
+
if (before.fields[name]) continue;
|
|
115
|
+
columns.push({
|
|
116
|
+
table: model,
|
|
117
|
+
name,
|
|
118
|
+
type: columnType(field.type),
|
|
119
|
+
notNull: false,
|
|
120
|
+
index: field.index === true || field.unique === true
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
tables,
|
|
126
|
+
columns
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** The index name for a column, in the camelCase the `0001_init` indexes are declared in. */
|
|
130
|
+
function indexName(table, column) {
|
|
131
|
+
return `${table}${column.charAt(0).toUpperCase()}${column.slice(1)}Idx`;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Build the Kysely migration for one plugin's delta. `down` is the exact inverse, and it runs the
|
|
135
|
+
* indexes off first: SQLite refuses to drop an indexed column.
|
|
136
|
+
*/
|
|
137
|
+
function pluginMigration(delta) {
|
|
138
|
+
return {
|
|
139
|
+
up: async (db) => {
|
|
140
|
+
for (const table of delta.tables) {
|
|
141
|
+
let builder = db.schema.createTable(table.name);
|
|
142
|
+
for (const column of table.columns) builder = builder.addColumn(column.name, column.type, (c) => {
|
|
143
|
+
let built = column.primaryKey ? c.primaryKey() : c;
|
|
144
|
+
if (column.notNull && !column.primaryKey) built = built.notNull();
|
|
145
|
+
if (column.unique) built = built.unique();
|
|
146
|
+
return built;
|
|
147
|
+
});
|
|
148
|
+
await builder.execute();
|
|
149
|
+
}
|
|
150
|
+
for (const column of delta.columns) await db.schema.alterTable(column.table).addColumn(column.name, column.type, (c) => c).execute();
|
|
151
|
+
for (const table of delta.tables) for (const column of table.columns) {
|
|
152
|
+
if (!column.index) continue;
|
|
153
|
+
await db.schema.createIndex(indexName(table.name, column.name)).on(table.name).column(column.name).execute();
|
|
154
|
+
}
|
|
155
|
+
for (const column of delta.columns) {
|
|
156
|
+
if (!column.index) continue;
|
|
157
|
+
await db.schema.createIndex(indexName(column.table, column.name)).on(column.table).column(column.name).execute();
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
down: async (db) => {
|
|
161
|
+
for (const column of delta.columns) if (column.index) await db.schema.dropIndex(indexName(column.table, column.name)).execute();
|
|
162
|
+
for (const column of delta.columns) await db.schema.alterTable(column.table).dropColumn(column.name).execute();
|
|
163
|
+
for (const table of [...delta.tables].reverse()) await db.schema.dropTable(table.name).execute();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The migration key for a plugin, e.g. `two-factor` → `0002_plugin_two_factor`.
|
|
169
|
+
*
|
|
170
|
+
* `0002` for every plugin, and that is not laziness. The four-digit lead is what
|
|
171
|
+
* `createMigrationRegistry` demands of a local key; within the auth namespace these all sort after
|
|
172
|
+
* `0001_init` and among themselves by plugin id, and **the order between two plugins is arbitrary by
|
|
173
|
+
* construction** — no plugin's tables reference another's, since each is derived against the same
|
|
174
|
+
* baseline. Numbering them `0002`, `0003`, … in config order would make the key of an already-applied
|
|
175
|
+
* migration change the moment a plugin was inserted before it, which is the one thing a ledger cannot
|
|
176
|
+
* survive.
|
|
177
|
+
*/
|
|
178
|
+
function pluginMigrationKey(id) {
|
|
179
|
+
return `0002_plugin_${id.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "")}`;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Derive everything the auth capability needs from an adopter's plugin list, in one pass.
|
|
183
|
+
*
|
|
184
|
+
* Migrations: one per plugin that has a schema, keyed by {@link pluginMigrationKey}. A plugin that adds
|
|
185
|
+
* no tables and no columns gets no migration and no ledger row — a plugin that is only endpoints has
|
|
186
|
+
* nothing to create. Extensions: one per plugin regardless, because a plugin with no tables still adds
|
|
187
|
+
* routes and still must not be invisible.
|
|
188
|
+
*
|
|
189
|
+
* Two plugins that claim the same table, or a plugin that claims one of the kit's own, are refused
|
|
190
|
+
* here rather than at `pithy migrate`: the second `createTable` would fail mid-run against a database
|
|
191
|
+
* that has no transactional DDL, leaving the first plugin's tables half-created. Naming both plugins
|
|
192
|
+
* and the table is the whole remedy — one of them takes a `schema: { … modelName }` override.
|
|
193
|
+
*/
|
|
194
|
+
function authPluginPlan(plugins) {
|
|
195
|
+
const migrations = {};
|
|
196
|
+
const extensions = [];
|
|
197
|
+
const claimed = /* @__PURE__ */ new Map();
|
|
198
|
+
for (const plugin of plugins) {
|
|
199
|
+
const delta = pluginSchemaDelta(plugin);
|
|
200
|
+
extensions.push({
|
|
201
|
+
id: plugin.id,
|
|
202
|
+
tables: delta.tables.map((table) => table.name)
|
|
203
|
+
});
|
|
204
|
+
for (const table of delta.tables) {
|
|
205
|
+
if (KIT_TABLE_NAMES.includes(table.name)) throw new ValidationError({
|
|
206
|
+
message: `The Better Auth "${plugin.id}" plugin declares a table the auth capability already owns: ${table.name}.`,
|
|
207
|
+
action: `Give it another name through the plugin's own \`schema: { … modelName }\` option — ${table.name} is created by the auth capability's 0001_init.`,
|
|
208
|
+
detail: `plugin "${plugin.id}" collides with kit table "${table.name}"`
|
|
209
|
+
});
|
|
210
|
+
const owner = claimed.get(table.name);
|
|
211
|
+
if (owner) throw new ValidationError({
|
|
212
|
+
message: `The Better Auth "${plugin.id}" and "${owner}" plugins both declare a ${table.name} table.`,
|
|
213
|
+
action: `Give one of them another name through its \`schema: { ${table.name}: { modelName: "…" } }\` option.`,
|
|
214
|
+
detail: `plugins "${owner}" and "${plugin.id}" both claim table "${table.name}"`
|
|
215
|
+
});
|
|
216
|
+
claimed.set(table.name, plugin.id);
|
|
217
|
+
}
|
|
218
|
+
if (delta.tables.length === 0 && delta.columns.length === 0) continue;
|
|
219
|
+
const key = pluginMigrationKey(plugin.id);
|
|
220
|
+
if (migrations[key]) throw new ValidationError({
|
|
221
|
+
message: `Two Better Auth plugins reduce to the same migration key: ${key}.`,
|
|
222
|
+
action: `Two plugin ids that differ only in punctuation cannot both be composed — rename one, or compose only one of them.`,
|
|
223
|
+
detail: `plugin "${plugin.id}" collides on migration key "${key}"`
|
|
224
|
+
});
|
|
225
|
+
migrations[key] = pluginMigration(delta);
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
migrations,
|
|
229
|
+
extensions
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
233
|
+
export { authPluginPlan, authSchemaOptions, pluginMigration, pluginMigrationKey, pluginSchemaDelta };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { DevLogin } from "@pithy-sh/core/src/seed/devLogin";
|
|
2
|
+
import { type SeedSet } from "@pithy-sh/core/src/seed/seed";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { Session } from "../data/betterAuth";
|
|
5
|
+
/**
|
|
6
|
+
* The dev-login seed set: a real, signed-in session for one seeded user, so local development does not
|
|
7
|
+
* begin with a magic-link round trip.
|
|
8
|
+
*
|
|
9
|
+
* Sign-in is passwordless by design, which is right in production and a tax in development — and more
|
|
10
|
+
* than a tax for anything automated, which cannot read a mailbox at all. The interesting part is *where*
|
|
11
|
+
* the work happens: the session is minted during seed, so the database holds a genuine row and the browser
|
|
12
|
+
* is handed a genuine cookie. Nothing about the request path is relaxed to make it work.
|
|
13
|
+
*
|
|
14
|
+
* Four guard rails, because what this writes is a live credential:
|
|
15
|
+
*
|
|
16
|
+
* - `environments: ["dev"]` — it can never be composed into staging or production.
|
|
17
|
+
* - No `~/.config/pithy/<project>/dev.json`, no session. The default stays "there is no way in but a magic link";
|
|
18
|
+
* opting in is a per-machine file outside the repo, so two developers on one checkout can differ.
|
|
19
|
+
* - The login file is transient, written under the gitignored `logs/` ({@link DEV_LOGIN_PATH}). A seeded
|
|
20
|
+
* cookie must never be committable.
|
|
21
|
+
* - The named user must be one this run actually creates. A session for a user nobody seeded is a dangling
|
|
22
|
+
* row, so `dev.json` is checked against `context.seeded` — the run's own inventory — and a miss fails
|
|
23
|
+
* saying who *was* seeded.
|
|
24
|
+
*
|
|
25
|
+
* Not an example set. It seeds no users of its own; it signs in as whoever the run creates — auth's example
|
|
26
|
+
* cast when the project enables `includeExamples`, the app's own users otherwise, both when both. An adopter
|
|
27
|
+
* should not have to turn on a fictional cast to get a dev login, and the cast is no more seeded than before:
|
|
28
|
+
* it still arrives only through `authExampleSeed`, which is still `example: true`.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Where this set sorts: last, at the ceiling. It depends on every set that can create a user — auth's own
|
|
32
|
+
* example set, and an adopter's app set, which sorts high by convention — so it sorts after all of them.
|
|
33
|
+
* Ties break on the namespaced key, but nothing rests on that: what this set needs to *know* comes from the
|
|
34
|
+
* composed plan, not from what has already been written, and the session row carries no foreign key.
|
|
35
|
+
*/
|
|
36
|
+
export declare const AUTH_DEV_SESSION_SEED_ORDER: number;
|
|
37
|
+
/**
|
|
38
|
+
* The cookie Better Auth reads the session from, in the one environment this set runs in.
|
|
39
|
+
*
|
|
40
|
+
* It used to be a literal beside a comment asserting that a `dev` base URL is not HTTPS. Nothing made
|
|
41
|
+
* that true: `baseURL` was one string for every environment, so an adopter whose production origin was
|
|
42
|
+
* HTTPS — every adopter — seeded this name while the running instance looked for `__Secure-` (#244).
|
|
43
|
+
* The session was there, the cookie was there, and `get-session` returned `null` with nothing logged.
|
|
44
|
+
*
|
|
45
|
+
* Now it is computed from the same two facts the composition computes its own name from: a `dev`
|
|
46
|
+
* composition serves over {@link DEV_PROTOCOL}, and {@link sessionCookieName} is the prefix rule. The
|
|
47
|
+
* host and port never enter it, which is what lets a seed name a cookie for a port not yet assigned.
|
|
48
|
+
* Still locked to the running Better Auth version by a test that reads the name off a live instance.
|
|
49
|
+
*/
|
|
50
|
+
export declare const DEV_SESSION_COOKIE_NAME: string;
|
|
51
|
+
/**
|
|
52
|
+
* The prefix every seeded dev session's id and token carry.
|
|
53
|
+
*
|
|
54
|
+
* It is what makes a dev session **findable without being told**, which is what the dev-login route
|
|
55
|
+
* needs: the route reads the session out of D1 and has no artifact to consult (a Worker has no
|
|
56
|
+
* filesystem). And it is what makes one identifiable at all — a `pithy_auth_sessions` row minted by a
|
|
57
|
+
* seed is otherwise indistinguishable from one a real sign-in created.
|
|
58
|
+
*/
|
|
59
|
+
export declare const DEV_SESSION_TOKEN_PREFIX = "dev-session-";
|
|
60
|
+
/** The developer's machine-local preferences for this project, read from `~/.config/pithy/<project>/dev.json`. */
|
|
61
|
+
export declare const DevPreferences: z.ZodObject<{
|
|
62
|
+
user: z.ZodString;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
export type DevPreferences = z.output<typeof DevPreferences>;
|
|
65
|
+
/**
|
|
66
|
+
* A user this run seeds, read back out of the composed plan.
|
|
67
|
+
*
|
|
68
|
+
* Narrow on purpose: the rows come from a set this capability does not own — an adopter's, most of the time —
|
|
69
|
+
* so they cross a trust boundary and are validated, but only for the two fields a session needs. A row with
|
|
70
|
+
* more in it is fine; a row without these is not a user this set can sign in as.
|
|
71
|
+
*/
|
|
72
|
+
export declare const SeededUser: z.ZodObject<{
|
|
73
|
+
id: z.ZodString;
|
|
74
|
+
email: z.ZodString;
|
|
75
|
+
}, z.core.$strip>;
|
|
76
|
+
export type SeededUser = z.output<typeof SeededUser>;
|
|
77
|
+
/** What {@link mintDevSession} produces: the row to write, and the artifact the browser is handed. */
|
|
78
|
+
export interface MintedDevSession {
|
|
79
|
+
/** The `pithy_auth_sessions` row, in app shape — re-encoded and validated by the seed writer. */
|
|
80
|
+
session: Session;
|
|
81
|
+
/** The dev-login artifact, written to `logs/dev-login.json` once the row lands. */
|
|
82
|
+
login: DevLogin;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Sign a value the way better-call does, so Better Auth accepts the cookie as one it signed itself:
|
|
86
|
+
* HMAC-SHA-256 over the value with the auth secret, base64, appended after a dot, then URI-encoded.
|
|
87
|
+
*
|
|
88
|
+
* Mirrored rather than imported: `signCookieValue` is internal to `better-call/dist/crypto`, not part of
|
|
89
|
+
* anything Better Auth re-exports, so importing it would bind us to a private path. Verified against
|
|
90
|
+
* better-call 1.3.6 — the version Better Auth 1.6.19 resolves — and pinned by a round-trip test that makes
|
|
91
|
+
* a real instance accept the result, which is the only check that actually matters.
|
|
92
|
+
*/
|
|
93
|
+
export declare function signCookieValue(value: string, secret: string): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* A short, stable fingerprint of the auth secret.
|
|
96
|
+
*
|
|
97
|
+
* Putting it in the session token makes the token deterministic across reseeds — the same cookie keeps
|
|
98
|
+
* working in every worktree once each is seeded, which is the whole point — while rotating the secret
|
|
99
|
+
* changes the token *and* invalidates every cookie signed with the old one, for free. A truncated digest,
|
|
100
|
+
* never the secret: the token is written to a file and read back by tooling.
|
|
101
|
+
*/
|
|
102
|
+
export declare function secretFingerprint(secret: string): Promise<string>;
|
|
103
|
+
/** Inputs to {@link mintDevSession}. `now` is a seam so the determinism tests do not depend on the clock. */
|
|
104
|
+
export interface MintDevSessionInput {
|
|
105
|
+
/** The seeded user to sign in as. */
|
|
106
|
+
user: SeededUser;
|
|
107
|
+
/** The Better Auth signing secret for this environment — never logged, never stored, never in an error. */
|
|
108
|
+
secret: string;
|
|
109
|
+
/** The moment the session is minted. Defaults to now. */
|
|
110
|
+
now?: Date;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Mint one deterministic dev session: the `pithy_auth_sessions` row and the signed cookie for it.
|
|
114
|
+
*
|
|
115
|
+
* The row id carries the fingerprint too, not just the token. Seed writes are `INSERT OR IGNORE`, so an
|
|
116
|
+
* id that ignored a rotation would keep the stale token alive under a row the next run refuses to replace.
|
|
117
|
+
*/
|
|
118
|
+
export declare function mintDevSession(input: MintDevSessionInput): Promise<MintedDevSession>;
|
|
119
|
+
/**
|
|
120
|
+
* The dev-login seed set. Composed by the auth capability; runs only in `dev`, only for a user this same run
|
|
121
|
+
* creates, and only when the developer has opted in with a `dev.json`.
|
|
122
|
+
*/
|
|
123
|
+
export declare const authDevSessionSeed: SeedSet;
|
|
124
|
+
//# sourceMappingURL=devSession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devSession.d.ts","sourceRoot":"","sources":["../../src/seeds/devSession.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkC,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5F,OAAO,EAKL,KAAK,OAAO,EACb,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI7C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,QAAiB,CAAC;AAM1D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,QAAkC,CAAC;AAEvE;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,iBAAiB,CAAC;AAQvD,kHAAkH;AAClH,eAAO,MAAM,cAAc;;iBAUxB,CAAC;AACJ,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAE7D;;;;;;GAMG;AACH,eAAO,MAAM,UAAU;;;iBAKgF,CAAC;AACxG,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAErD,sGAAsG;AACtG,MAAM,WAAW,gBAAgB;IAC/B,iGAAiG;IACjG,OAAO,EAAE,OAAO,CAAC;IACjB,mFAAmF;IACnF,KAAK,EAAE,QAAQ,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAWpF;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAKvE;AAED,6GAA6G;AAC7G,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,IAAI,EAAE,UAAU,CAAC;IACjB,2GAA2G;IAC3G,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA6B1F;AA6CD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,OA6B/B,CAAC"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { Session } from "../data/betterAuth.js";
|
|
2
|
+
import { DEV_PROTOCOL, sessionCookieName } from "../http/baseUrl.js";
|
|
3
|
+
import { AUTH_SESSION_SECRET } from "../instance/secrets.js";
|
|
4
|
+
import { ValidationError, fromZodError } from "@pithy-sh/core/src/error/pithyError";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { DEV_LOGIN_FILE, DevLogin } from "@pithy-sh/core/src/seed/devLogin";
|
|
7
|
+
import { normalizeAddress } from "@pithy-sh/core/src/address/address";
|
|
8
|
+
import { MAX_SEED_ORDER } from "@pithy-sh/core/src/seed/compose";
|
|
9
|
+
import { d1SeedGroup, defineSeed } from "@pithy-sh/core/src/seed/seed";
|
|
10
|
+
//#region src/seeds/devSession.ts
|
|
11
|
+
/**
|
|
12
|
+
* The dev-login seed set: a real, signed-in session for one seeded user, so local development does not
|
|
13
|
+
* begin with a magic-link round trip.
|
|
14
|
+
*
|
|
15
|
+
* Sign-in is passwordless by design, which is right in production and a tax in development — and more
|
|
16
|
+
* than a tax for anything automated, which cannot read a mailbox at all. The interesting part is *where*
|
|
17
|
+
* the work happens: the session is minted during seed, so the database holds a genuine row and the browser
|
|
18
|
+
* is handed a genuine cookie. Nothing about the request path is relaxed to make it work.
|
|
19
|
+
*
|
|
20
|
+
* Four guard rails, because what this writes is a live credential:
|
|
21
|
+
*
|
|
22
|
+
* - `environments: ["dev"]` — it can never be composed into staging or production.
|
|
23
|
+
* - No `~/.config/pithy/<project>/dev.json`, no session. The default stays "there is no way in but a magic link";
|
|
24
|
+
* opting in is a per-machine file outside the repo, so two developers on one checkout can differ.
|
|
25
|
+
* - The login file is transient, written under the gitignored `logs/` ({@link DEV_LOGIN_PATH}). A seeded
|
|
26
|
+
* cookie must never be committable.
|
|
27
|
+
* - The named user must be one this run actually creates. A session for a user nobody seeded is a dangling
|
|
28
|
+
* row, so `dev.json` is checked against `context.seeded` — the run's own inventory — and a miss fails
|
|
29
|
+
* saying who *was* seeded.
|
|
30
|
+
*
|
|
31
|
+
* Not an example set. It seeds no users of its own; it signs in as whoever the run creates — auth's example
|
|
32
|
+
* cast when the project enables `includeExamples`, the app's own users otherwise, both when both. An adopter
|
|
33
|
+
* should not have to turn on a fictional cast to get a dev login, and the cast is no more seeded than before:
|
|
34
|
+
* it still arrives only through `authExampleSeed`, which is still `example: true`.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Where this set sorts: last, at the ceiling. It depends on every set that can create a user — auth's own
|
|
38
|
+
* example set, and an adopter's app set, which sorts high by convention — so it sorts after all of them.
|
|
39
|
+
* Ties break on the namespaced key, but nothing rests on that: what this set needs to *know* comes from the
|
|
40
|
+
* composed plan, not from what has already been written, and the session row carries no foreign key.
|
|
41
|
+
*/
|
|
42
|
+
const AUTH_DEV_SESSION_SEED_ORDER = MAX_SEED_ORDER;
|
|
43
|
+
/** The composed registry coordinates of the users table this set reads and signs in as. */
|
|
44
|
+
const USERS_DATABASE = "app";
|
|
45
|
+
const USERS_TABLE = "pithyAuthUsers";
|
|
46
|
+
/**
|
|
47
|
+
* The cookie Better Auth reads the session from, in the one environment this set runs in.
|
|
48
|
+
*
|
|
49
|
+
* It used to be a literal beside a comment asserting that a `dev` base URL is not HTTPS. Nothing made
|
|
50
|
+
* that true: `baseURL` was one string for every environment, so an adopter whose production origin was
|
|
51
|
+
* HTTPS — every adopter — seeded this name while the running instance looked for `__Secure-` (#244).
|
|
52
|
+
* The session was there, the cookie was there, and `get-session` returned `null` with nothing logged.
|
|
53
|
+
*
|
|
54
|
+
* Now it is computed from the same two facts the composition computes its own name from: a `dev`
|
|
55
|
+
* composition serves over {@link DEV_PROTOCOL}, and {@link sessionCookieName} is the prefix rule. The
|
|
56
|
+
* host and port never enter it, which is what lets a seed name a cookie for a port not yet assigned.
|
|
57
|
+
* Still locked to the running Better Auth version by a test that reads the name off a live instance.
|
|
58
|
+
*/
|
|
59
|
+
const DEV_SESSION_COOKIE_NAME = sessionCookieName(DEV_PROTOCOL);
|
|
60
|
+
/**
|
|
61
|
+
* The prefix every seeded dev session's id and token carry.
|
|
62
|
+
*
|
|
63
|
+
* It is what makes a dev session **findable without being told**, which is what the dev-login route
|
|
64
|
+
* needs: the route reads the session out of D1 and has no artifact to consult (a Worker has no
|
|
65
|
+
* filesystem). And it is what makes one identifiable at all — a `pithy_auth_sessions` row minted by a
|
|
66
|
+
* seed is otherwise indistinguishable from one a real sign-in created.
|
|
67
|
+
*/
|
|
68
|
+
const DEV_SESSION_TOKEN_PREFIX = "dev-session-";
|
|
69
|
+
/** How long a seeded session lives. Long, because reseeding to restore a dev login is the friction this removes. */
|
|
70
|
+
const DEV_SESSION_LIFETIME_MS = 31536e6;
|
|
71
|
+
/** Bytes of the secret digest kept as the token's fingerprint — enough to separate secrets, short enough to read. */
|
|
72
|
+
const FINGERPRINT_BYTES = 4;
|
|
73
|
+
/** The developer's machine-local preferences for this project, read from `~/.config/pithy/<project>/dev.json`. */
|
|
74
|
+
const DevPreferences = z.object({ user: z.string().describe("The email of the seeded user to sign in as. Must be a user this seed run creates, or the seed fails rather than signing in as nobody.") }).describe("A developer's machine-local dev preferences, from the Pithy config directory (`~/.config/pithy/<project>/dev.json`, or `%APPDATA%\\pithy\\<project>\\dev.json` on Windows) — outside the repo, so opting in needs no commit.");
|
|
75
|
+
/**
|
|
76
|
+
* A user this run seeds, read back out of the composed plan.
|
|
77
|
+
*
|
|
78
|
+
* Narrow on purpose: the rows come from a set this capability does not own — an adopter's, most of the time —
|
|
79
|
+
* so they cross a trust boundary and are validated, but only for the two fields a session needs. A row with
|
|
80
|
+
* more in it is fine; a row without these is not a user this set can sign in as.
|
|
81
|
+
*/
|
|
82
|
+
const SeededUser = z.object({
|
|
83
|
+
id: z.string().min(1).describe("The user id the session's `userId` points at."),
|
|
84
|
+
email: z.string().min(1).describe("The email `dev.json` names, and the login artifact records.")
|
|
85
|
+
}).describe("A seeded `pithy_auth_users` row, narrowed to what minting a dev session for it requires.");
|
|
86
|
+
/**
|
|
87
|
+
* Sign a value the way better-call does, so Better Auth accepts the cookie as one it signed itself:
|
|
88
|
+
* HMAC-SHA-256 over the value with the auth secret, base64, appended after a dot, then URI-encoded.
|
|
89
|
+
*
|
|
90
|
+
* Mirrored rather than imported: `signCookieValue` is internal to `better-call/dist/crypto`, not part of
|
|
91
|
+
* anything Better Auth re-exports, so importing it would bind us to a private path. Verified against
|
|
92
|
+
* better-call 1.3.6 — the version Better Auth 1.6.19 resolves — and pinned by a round-trip test that makes
|
|
93
|
+
* a real instance accept the result, which is the only check that actually matters.
|
|
94
|
+
*/
|
|
95
|
+
async function signCookieValue(value, secret) {
|
|
96
|
+
const key = await crypto.subtle.importKey("raw", new TextEncoder().encode(secret), {
|
|
97
|
+
name: "HMAC",
|
|
98
|
+
hash: "SHA-256"
|
|
99
|
+
}, false, ["sign"]);
|
|
100
|
+
const signature = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(value));
|
|
101
|
+
const base64 = btoa(String.fromCharCode(...new Uint8Array(signature)));
|
|
102
|
+
return encodeURIComponent(`${value}.${base64}`);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A short, stable fingerprint of the auth secret.
|
|
106
|
+
*
|
|
107
|
+
* Putting it in the session token makes the token deterministic across reseeds — the same cookie keeps
|
|
108
|
+
* working in every worktree once each is seeded, which is the whole point — while rotating the secret
|
|
109
|
+
* changes the token *and* invalidates every cookie signed with the old one, for free. A truncated digest,
|
|
110
|
+
* never the secret: the token is written to a file and read back by tooling.
|
|
111
|
+
*/
|
|
112
|
+
async function secretFingerprint(secret) {
|
|
113
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(secret));
|
|
114
|
+
return Array.from(new Uint8Array(digest).slice(0, FINGERPRINT_BYTES)).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Mint one deterministic dev session: the `pithy_auth_sessions` row and the signed cookie for it.
|
|
118
|
+
*
|
|
119
|
+
* The row id carries the fingerprint too, not just the token. Seed writes are `INSERT OR IGNORE`, so an
|
|
120
|
+
* id that ignored a rotation would keep the stale token alive under a row the next run refuses to replace.
|
|
121
|
+
*/
|
|
122
|
+
async function mintDevSession(input) {
|
|
123
|
+
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
124
|
+
const expiresAt = new Date(now.getTime() + DEV_SESSION_LIFETIME_MS);
|
|
125
|
+
const fingerprint = await secretFingerprint(input.secret);
|
|
126
|
+
const token = `${DEV_SESSION_TOKEN_PREFIX}${input.user.id}-${fingerprint}`;
|
|
127
|
+
return {
|
|
128
|
+
session: {
|
|
129
|
+
id: token,
|
|
130
|
+
token,
|
|
131
|
+
userId: input.user.id,
|
|
132
|
+
expiresAt,
|
|
133
|
+
createdAt: now,
|
|
134
|
+
updatedAt: now,
|
|
135
|
+
ipAddress: "127.0.0.1",
|
|
136
|
+
userAgent: "pithy seed (dev login)",
|
|
137
|
+
deviceId: null,
|
|
138
|
+
familyId: null
|
|
139
|
+
},
|
|
140
|
+
login: {
|
|
141
|
+
email: input.user.email,
|
|
142
|
+
userId: input.user.id,
|
|
143
|
+
cookieName: DEV_SESSION_COOKIE_NAME,
|
|
144
|
+
cookieValue: await signCookieValue(token, input.secret),
|
|
145
|
+
expiresAt
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The users this run creates, whichever set contributes them.
|
|
151
|
+
*
|
|
152
|
+
* A row that does not parse is skipped rather than fatal: it belongs to some other set, which owns its own
|
|
153
|
+
* validation, and failing the dev login over someone else's fixture would be the wrong place to find out.
|
|
154
|
+
*/
|
|
155
|
+
function seededUsers(seeded) {
|
|
156
|
+
return seeded(USERS_DATABASE, USERS_TABLE).flatMap((row) => {
|
|
157
|
+
const parsed = SeededUser.safeParse(row);
|
|
158
|
+
return parsed.success ? [parsed.data] : [];
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/** What to do about it — the actionable half of every failure here, and never a guess. */
|
|
162
|
+
function nameOneOf(users) {
|
|
163
|
+
if (users.length === 0) return "This run seeds no users at all. Add a user fixture to your app's seed set, or turn on seed.includeExamples for the example cast.";
|
|
164
|
+
return `Name one of the users this run seeds instead: ${users.map((user) => user.email).join(", ")}.`;
|
|
165
|
+
}
|
|
166
|
+
/** Resolve the preference file into the user to sign in as, or fail saying who this run does seed. */
|
|
167
|
+
function requireUser(preferences, users) {
|
|
168
|
+
const parsed = DevPreferences.safeParse(preferences);
|
|
169
|
+
if (!parsed.success) throw fromZodError(parsed.error, {
|
|
170
|
+
message: "The dev.json preference file does not name a user.",
|
|
171
|
+
action: `Set { "user": "<email>" } in it. ${nameOneOf(users)}`
|
|
172
|
+
});
|
|
173
|
+
const wanted = normalizeAddress(parsed.data.user);
|
|
174
|
+
const user = users.find((candidate) => normalizeAddress(candidate.email) === wanted);
|
|
175
|
+
if (!user) throw new ValidationError({
|
|
176
|
+
message: `dev.json asks to sign in as ${parsed.data.user}, which this seed run does not create.`,
|
|
177
|
+
action: nameOneOf(users)
|
|
178
|
+
});
|
|
179
|
+
return user;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The dev-login seed set. Composed by the auth capability; runs only in `dev`, only for a user this same run
|
|
183
|
+
* creates, and only when the developer has opted in with a `dev.json`.
|
|
184
|
+
*/
|
|
185
|
+
const authDevSessionSeed = defineSeed({
|
|
186
|
+
name: "dev-session",
|
|
187
|
+
order: AUTH_DEV_SESSION_SEED_ORDER,
|
|
188
|
+
environments: ["dev"],
|
|
189
|
+
prepare: async (context) => {
|
|
190
|
+
if (context.preferences === void 0 || context.preferences === null) return {};
|
|
191
|
+
const user = requireUser(context.preferences, seededUsers(context.seeded));
|
|
192
|
+
const secret = await context.secret(AUTH_SESSION_SECRET);
|
|
193
|
+
if (!secret) throw new ValidationError({
|
|
194
|
+
message: "Cannot mint a dev session without this environment's auth secret.",
|
|
195
|
+
action: `Add ${AUTH_SESSION_SECRET} to this project's dev secrets file — pithy doctor prints its path — then seed again.`
|
|
196
|
+
});
|
|
197
|
+
const minted = await mintDevSession({
|
|
198
|
+
user,
|
|
199
|
+
secret
|
|
200
|
+
});
|
|
201
|
+
return {
|
|
202
|
+
d1: [d1SeedGroup("app", "pithyAuthSessions", Session, [minted.session])],
|
|
203
|
+
artifacts: [{
|
|
204
|
+
file: DEV_LOGIN_FILE,
|
|
205
|
+
contents: `${JSON.stringify(DevLogin.encode(minted.login), null, 2)}\n`
|
|
206
|
+
}]
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
//#endregion
|
|
211
|
+
export { AUTH_DEV_SESSION_SEED_ORDER, DEV_SESSION_COOKIE_NAME, DEV_SESSION_TOKEN_PREFIX, DevPreferences, SeededUser, authDevSessionSeed, mintDevSession, secretFingerprint, signCookieValue };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type SeedSet } from "@pithy-sh/core/src/seed/seed";
|
|
2
|
+
/**
|
|
3
|
+
* The canonical demo cast ({@link EXAMPLE_IDENTITIES}) as `pithy_auth_users` rows — the shared,
|
|
4
|
+
* passwordless test identities every other capability's example seed references by `userId`. No
|
|
5
|
+
* `Account`/`Session`/password rows: these are the users, not a signed-in session, and Pithy is
|
|
6
|
+
* passwordless-only regardless. `emailVerified` is true so a seeded identity behaves exactly like a
|
|
7
|
+
* user who has completed magic-link/OTP verification. Composed in only when the project turns on
|
|
8
|
+
* `seed.includeExamples` (`pithy.config.ts`), and only for `dev` and `staging` — an example fixture
|
|
9
|
+
* never targets production, regardless of that setting.
|
|
10
|
+
*/
|
|
11
|
+
export declare const authExampleSeed: SeedSet;
|
|
12
|
+
//# sourceMappingURL=example.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../src/seeds/example.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2B,KAAK,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAUrF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,EAAE,OAwB5B,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { User } from "../data/betterAuth.js";
|
|
2
|
+
import { d1SeedGroup, defineSeed } from "@pithy-sh/core/src/seed/seed";
|
|
3
|
+
import { EXAMPLE_IDENTITIES } from "@pithy-sh/core/src/seed/exampleIdentities";
|
|
4
|
+
/**
|
|
5
|
+
* The canonical demo cast ({@link EXAMPLE_IDENTITIES}) as `pithy_auth_users` rows — the shared,
|
|
6
|
+
* passwordless test identities every other capability's example seed references by `userId`. No
|
|
7
|
+
* `Account`/`Session`/password rows: these are the users, not a signed-in session, and Pithy is
|
|
8
|
+
* passwordless-only regardless. `emailVerified` is true so a seeded identity behaves exactly like a
|
|
9
|
+
* user who has completed magic-link/OTP verification. Composed in only when the project turns on
|
|
10
|
+
* `seed.includeExamples` (`pithy.config.ts`), and only for `dev` and `staging` — an example fixture
|
|
11
|
+
* never targets production, regardless of that setting.
|
|
12
|
+
*/
|
|
13
|
+
const authExampleSeed = defineSeed({
|
|
14
|
+
name: "example",
|
|
15
|
+
order: 100,
|
|
16
|
+
environments: ["dev", "staging"],
|
|
17
|
+
example: true,
|
|
18
|
+
d1: [d1SeedGroup("app", "pithyAuthUsers", User, EXAMPLE_IDENTITIES.map((identity) => ({
|
|
19
|
+
id: identity.id,
|
|
20
|
+
name: identity.name,
|
|
21
|
+
email: identity.email,
|
|
22
|
+
emailVerified: true,
|
|
23
|
+
image: null,
|
|
24
|
+
locale: null,
|
|
25
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
26
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
27
|
+
})))]
|
|
28
|
+
});
|
|
29
|
+
//#endregion
|
|
30
|
+
export { authExampleSeed };
|