@pithy-sh/auth 0.10.0 → 0.11.0
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/README.md +1 -1
- package/dist/admin/users.js +1 -1
- package/dist/audit/actions.d.ts +19 -0
- package/dist/audit/actions.d.ts.map +1 -1
- package/dist/audit/actions.js +20 -1
- package/dist/audit/emit.d.ts +2 -0
- package/dist/audit/emit.d.ts.map +1 -1
- package/dist/audit/emit.js +1 -1
- package/dist/capability.d.ts +19 -0
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +20 -3
- package/dist/data/tables.d.ts +1 -0
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/userLifecycle.d.ts +1 -0
- package/dist/data/userLifecycle.d.ts.map +1 -1
- package/dist/data/userLifecycle.js +2 -1
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +270 -5
- package/dist/http/guards.d.ts +8 -7
- package/dist/http/guards.d.ts.map +1 -1
- package/dist/http/guards.js +38 -7
- package/dist/http/middleware.d.ts +25 -1
- package/dist/http/middleware.d.ts.map +1 -1
- package/dist/http/middleware.js +44 -3
- package/dist/http/responses.d.ts +180 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +142 -1
- package/dist/http/routes.d.ts +1 -0
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +45 -3
- package/dist/http/schemas.d.ts +57 -0
- package/dist/http/schemas.d.ts.map +1 -1
- package/dist/http/schemas.js +51 -1
- package/dist/http/views.d.ts +39 -2
- package/dist/http/views.d.ts.map +1 -1
- package/dist/http/views.js +105 -1
- package/dist/instance/auth.d.ts.map +1 -1
- package/dist/instance/auth.js +2 -2
- package/dist/lifecycle/audited.d.ts +48 -0
- package/dist/lifecycle/audited.d.ts.map +1 -0
- package/dist/lifecycle/audited.js +65 -0
- package/dist/lifecycle/enforce.d.ts +37 -2
- package/dist/lifecycle/enforce.d.ts.map +1 -1
- package/dist/lifecycle/enforce.js +46 -5
- package/dist/lifecycle/reason.d.ts +11 -0
- package/dist/lifecycle/reason.d.ts.map +1 -0
- package/dist/lifecycle/reason.js +13 -0
- package/dist/lifecycle/request.d.ts +5 -2
- package/dist/lifecycle/request.d.ts.map +1 -1
- package/dist/lifecycle/request.js +6 -2
- package/dist/lifecycle/transitions.d.ts +158 -18
- package/dist/lifecycle/transitions.d.ts.map +1 -1
- package/dist/lifecycle/transitions.js +344 -70
- package/dist/migrations/0005_purge_once.d.ts +22 -0
- package/dist/migrations/0005_purge_once.d.ts.map +1 -0
- package/dist/migrations/0005_purge_once.js +35 -0
- package/dist/migrations/pluginTables.d.ts +8 -0
- package/dist/migrations/pluginTables.d.ts.map +1 -1
- package/dist/migrations/pluginTables.js +8 -1
- package/dist/migrations/set.d.ts +2 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +4 -2
- package/dist/purge/contribution.d.ts +47 -0
- package/dist/purge/contribution.d.ts.map +1 -0
- package/dist/purge/contribution.js +141 -0
- package/dist/purge/retryPolicy.d.ts +22 -0
- package/dist/purge/retryPolicy.d.ts.map +1 -0
- package/dist/purge/retryPolicy.js +26 -0
- package/dist/purge/run.d.ts +88 -0
- package/dist/purge/run.d.ts.map +1 -0
- package/dist/purge/run.js +102 -0
- package/dist/purge/specs.d.ts +71 -0
- package/dist/purge/specs.d.ts.map +1 -0
- package/dist/purge/specs.js +72 -0
- package/dist/purge/start.d.ts +42 -0
- package/dist/purge/start.d.ts.map +1 -0
- package/dist/purge/start.js +37 -0
- package/dist/purge/workflow.d.ts +58 -0
- package/dist/purge/workflow.d.ts.map +1 -0
- package/dist/purge/workflow.js +96 -0
- package/dist/test-utils/accountFootprint.d.ts +10 -0
- package/dist/test-utils/accountFootprint.d.ts.map +1 -0
- package/dist/test-utils/accountFootprint.js +44 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/account-lifecycle.md +123 -11
- package/package.json +5 -5
- package/pithy.manifest.json +1 -1
- package/src/audit/actions.ts +19 -0
- package/src/audit/emit.ts +3 -1
- package/src/capability.ts +48 -1
- package/src/data/userLifecycle.ts +4 -1
- package/src/http/adminRoutes.ts +398 -2
- package/src/http/guards.ts +39 -7
- package/src/http/middleware.ts +45 -2
- package/src/http/responses.ts +245 -0
- package/src/http/routes.ts +55 -3
- package/src/http/schemas.ts +110 -0
- package/src/http/views.ts +147 -2
- package/src/instance/auth.ts +7 -2
- package/src/lifecycle/audited.ts +104 -0
- package/src/lifecycle/enforce.ts +55 -5
- package/src/lifecycle/reason.ts +11 -0
- package/src/lifecycle/request.ts +10 -2
- package/src/lifecycle/transitions.ts +482 -93
- package/src/migrations/0005_purge_once.ts +42 -0
- package/src/migrations/pluginTables.ts +19 -1
- package/src/migrations/set.ts +3 -1
- package/src/purge/contribution.ts +191 -0
- package/src/purge/retryPolicy.ts +26 -0
- package/src/purge/run.ts +185 -0
- package/src/purge/specs.ts +95 -0
- package/src/purge/start.ts +79 -0
- package/src/purge/workflow.ts +144 -0
- package/src/test-utils/accountFootprint.ts +95 -0
- package/src/version.generated.ts +1 -1
package/src/http/responses.ts
CHANGED
|
@@ -198,6 +198,234 @@ export const AdminDeviceRevokeResponse = z
|
|
|
198
198
|
.describe("How many sessions the device revocation ended, and whether the registry row went with them.");
|
|
199
199
|
export type AdminDeviceRevokeResponse = z.output<typeof AdminDeviceRevokeResponse>;
|
|
200
200
|
|
|
201
|
+
/**
|
|
202
|
+
* `POST {base}/admin/users/:userId/suspend` (#621).
|
|
203
|
+
*
|
|
204
|
+
* The suspension the account is now under, how many sessions ended with it, and whether the person was told.
|
|
205
|
+
* Not the reason: the caller wrote it, the trail keeps it, and echoing it back would put it in one more place
|
|
206
|
+
* a dashboard logs.
|
|
207
|
+
*/
|
|
208
|
+
export const AdminUserSuspendResponse = z
|
|
209
|
+
.object({
|
|
210
|
+
userId: z.string().describe("The account suspended, as `pithy_auth_users.id` stores it."),
|
|
211
|
+
state: z.literal("suspended").describe("Where the account stands now. Every sign-in and refresh is refused."),
|
|
212
|
+
outcome: z
|
|
213
|
+
.enum(["suspended", "updated"])
|
|
214
|
+
.describe(
|
|
215
|
+
"`suspended` when this call suspended an account in good standing; `updated` when it was already suspended and this call restated the reason and the end.",
|
|
216
|
+
),
|
|
217
|
+
suspendedAt: z.iso
|
|
218
|
+
.datetime()
|
|
219
|
+
.describe("When the suspension in force began, ISO-8601. A restatement keeps the original start."),
|
|
220
|
+
suspendedUntil: z.iso
|
|
221
|
+
.datetime()
|
|
222
|
+
.nullable()
|
|
223
|
+
.describe("When it ends by itself, ISO-8601, with nothing written to end it. Null lasts until a reinstatement."),
|
|
224
|
+
sessionsRevoked: RevokedCount,
|
|
225
|
+
mailed: z
|
|
226
|
+
.boolean()
|
|
227
|
+
.describe(
|
|
228
|
+
"Whether the account-suspended mail was enqueued. False for `notify: false`, when the config turns it off, or when no email capability is composed.",
|
|
229
|
+
),
|
|
230
|
+
})
|
|
231
|
+
.describe("A suspended account: since when, until when, how many sessions it cost, and whether the person was told.");
|
|
232
|
+
export type AdminUserSuspendResponse = z.output<typeof AdminUserSuspendResponse>;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* `POST {base}/admin/users/:userId/reinstate` (#621).
|
|
236
|
+
*
|
|
237
|
+
* No session count: a reinstatement restores none. The person signs in again.
|
|
238
|
+
*/
|
|
239
|
+
export const AdminUserReinstateResponse = z
|
|
240
|
+
.object({
|
|
241
|
+
userId: z.string().describe("The account reinstated, as `pithy_auth_users.id` stores it."),
|
|
242
|
+
state: z.literal("active").describe("Where the account stands now. It can sign in again."),
|
|
243
|
+
outcome: z
|
|
244
|
+
.enum(["reinstated", "unchanged"])
|
|
245
|
+
.describe(
|
|
246
|
+
"`reinstated` when this call lifted a suspension; `unchanged` when there was none in force — never suspended, or past its end — and nothing was written.",
|
|
247
|
+
),
|
|
248
|
+
mailed: z
|
|
249
|
+
.boolean()
|
|
250
|
+
.describe(
|
|
251
|
+
"Whether the account-reinstated mail was enqueued. Always false for `unchanged`, and on the same rule as a suspension's otherwise.",
|
|
252
|
+
),
|
|
253
|
+
})
|
|
254
|
+
.describe("A reinstated account, and whether the person was told. Its revoked sessions stay revoked.");
|
|
255
|
+
export type AdminUserReinstateResponse = z.output<typeof AdminUserReinstateResponse>;
|
|
256
|
+
|
|
257
|
+
/** When the purge may erase a deleted account, ISO-8601. */
|
|
258
|
+
const PurgeAfter = z.iso
|
|
259
|
+
.datetime()
|
|
260
|
+
.describe(
|
|
261
|
+
"When the purge may erase the account, ISO-8601. It can be restored until then; a hard deletion's is the moment it was deleted.",
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* `DELETE {base}/admin/users/:userId` (#622).
|
|
266
|
+
*
|
|
267
|
+
* What the deletion left in force, how many sessions ended with it, whether the person was told, and what
|
|
268
|
+
* became of the purge. Not the reason: the caller wrote it and the trail keeps it.
|
|
269
|
+
*/
|
|
270
|
+
export const AdminUserDeleteResponse = z
|
|
271
|
+
.object({
|
|
272
|
+
userId: z.string().describe("The account deleted, as `pithy_auth_users.id` stores it."),
|
|
273
|
+
state: z.literal("deleted").describe("Where the account stands now. Every sign-in and refresh is refused."),
|
|
274
|
+
mode: z.enum(["soft", "hard"]).describe("The mode this call ran in — `soft` unless the caller named `hard`."),
|
|
275
|
+
outcome: z
|
|
276
|
+
.enum(["deleted", "brought_forward", "unchanged"])
|
|
277
|
+
.describe(
|
|
278
|
+
"`deleted` when this call deleted an account in good standing; `brought_forward` when a hard deletion moved an already-deleted account's purge to now; `unchanged` when it was already deleted and there was nothing to move.",
|
|
279
|
+
),
|
|
280
|
+
deletedAt: z.iso.datetime().describe("When the account was deleted, ISO-8601. Kept by a deletion brought forward."),
|
|
281
|
+
purgeAfter: PurgeAfter,
|
|
282
|
+
purge: z
|
|
283
|
+
.enum(["scheduled", "started", "pending"])
|
|
284
|
+
.describe(
|
|
285
|
+
"`scheduled`: the daily purge erases it once `purgeAfter` passes. `started`: the purge Workflow was started by this call. `pending`: the purge is due and this Worker binds no purge Workflow to start, so it runs once one is bound.",
|
|
286
|
+
),
|
|
287
|
+
sessionsRevoked: RevokedCount,
|
|
288
|
+
mailed: z
|
|
289
|
+
.boolean()
|
|
290
|
+
.describe(
|
|
291
|
+
"Whether the deletion-scheduled mail was enqueued. Always false for `hard`, whose mail the purge sends, for `notify: false`, and when the config turns it off.",
|
|
292
|
+
),
|
|
293
|
+
})
|
|
294
|
+
.describe("A deleted account: when, until when it can be restored, what became of the purge, and its sessions.");
|
|
295
|
+
export type AdminUserDeleteResponse = z.output<typeof AdminUserDeleteResponse>;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* `POST {base}/admin/users/:userId/restore` (#622). No session count: a restoration restores none.
|
|
299
|
+
*/
|
|
300
|
+
export const AdminUserRestoreResponse = z
|
|
301
|
+
.object({
|
|
302
|
+
userId: z.string().describe("The account restored, as `pithy_auth_users.id` stores it."),
|
|
303
|
+
state: z
|
|
304
|
+
.enum(["active", "suspended"])
|
|
305
|
+
.describe(
|
|
306
|
+
"Where the account stands now: `active`, or `suspended` when a suspension it was under before the deletion is still in force.",
|
|
307
|
+
),
|
|
308
|
+
outcome: z
|
|
309
|
+
.enum(["restored", "unchanged"])
|
|
310
|
+
.describe("`restored` when this call restored a deleted account; `unchanged` when it was not deleted."),
|
|
311
|
+
})
|
|
312
|
+
.describe("A restored account, inside its purge window. Its revoked sessions stay revoked.");
|
|
313
|
+
export type AdminUserRestoreResponse = z.output<typeof AdminUserRestoreResponse>;
|
|
314
|
+
|
|
315
|
+
/** One provider link an account holds, as an export carries it — no provider token. */
|
|
316
|
+
const AuthExportProvider = z
|
|
317
|
+
.object({
|
|
318
|
+
providerId: z.string().describe("The sign-in provider's slug — `google`, `apple`, `github`."),
|
|
319
|
+
createdAt: z.iso.datetime().describe("When the provider was linked, ISO-8601."),
|
|
320
|
+
})
|
|
321
|
+
.describe("One sign-in provider linked to the account. The provider's tokens are credentials and are not here.");
|
|
322
|
+
|
|
323
|
+
/** One transition in an account's history, as an export carries it — not who made it. */
|
|
324
|
+
const AuthExportTransition = z
|
|
325
|
+
.object({
|
|
326
|
+
action: z
|
|
327
|
+
.string()
|
|
328
|
+
.describe("What happened: `suspended`, `reinstated`, `deleted`, `restored`, `purge_step`, `purged`."),
|
|
329
|
+
actorType: z.string().describe("Who made it: `control-plane`, `user` (the account's holder), or `system`."),
|
|
330
|
+
reason: z.string().nullable().describe("The reason given, in the words of whoever made the transition, or null."),
|
|
331
|
+
suspendedUntil: z.iso.datetime().nullable().describe("For a suspension, when it ends by itself, ISO-8601."),
|
|
332
|
+
createdAt: z.iso.datetime().describe("When it happened, ISO-8601."),
|
|
333
|
+
})
|
|
334
|
+
.describe(
|
|
335
|
+
"One transition in the account's history. The operator's identity is theirs, not the person's, so it is not here.",
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* What `@pithy-sh/auth` holds about one account, as its purge contribution exports it (#622) — the `data` of
|
|
340
|
+
* the `auth` entry in an export.
|
|
341
|
+
*
|
|
342
|
+
* The person's own data and none of their credentials: no session token, no provider token, no push token.
|
|
343
|
+
* Every list is whole, because an export that stopped at a bound would answer an access request with part of
|
|
344
|
+
* an answer.
|
|
345
|
+
*/
|
|
346
|
+
export const AuthUserExport = z
|
|
347
|
+
.object({
|
|
348
|
+
user: AdminUserView.extend({
|
|
349
|
+
suspendedAt: z.iso.datetime().nullable().describe("When a suspension in force began, ISO-8601, or null."),
|
|
350
|
+
suspendedUntil: z.iso.datetime().nullable().describe("When that suspension ends by itself, ISO-8601, or null."),
|
|
351
|
+
deletedAt: z.iso.datetime().nullable().describe("When the account was deleted, ISO-8601, or null."),
|
|
352
|
+
purgeAfter: z.iso.datetime().nullable().describe("When the purge may erase it, ISO-8601, or null."),
|
|
353
|
+
}).describe("The account itself, with where it stands."),
|
|
354
|
+
sessions: z.array(AdminSessionView).describe("Every live session, newest first. Without the tokens."),
|
|
355
|
+
providers: z.array(AuthExportProvider).describe("Every linked sign-in provider."),
|
|
356
|
+
devices: z
|
|
357
|
+
.array(AdminDeviceView)
|
|
358
|
+
.describe("Every registered device, most recently seen first. Without push tokens."),
|
|
359
|
+
history: z.array(AuthExportTransition).describe("Every lifecycle transition, oldest first."),
|
|
360
|
+
plugins: z
|
|
361
|
+
.record(z.string(), z.array(z.record(z.string(), z.unknown())))
|
|
362
|
+
.describe(
|
|
363
|
+
"The account's rows in each table a composed Better Auth plugin created keyed by `userId` — two-factor, passkeys, API keys — keyed by table. Without a column that holds a credential. Empty when no such plugin is composed.",
|
|
364
|
+
),
|
|
365
|
+
})
|
|
366
|
+
.describe("Everything `@pithy-sh/auth` holds about one account, without a credential.");
|
|
367
|
+
export type AuthUserExport = z.output<typeof AuthUserExport>;
|
|
368
|
+
|
|
369
|
+
/** Fields every capability's export entry carries. */
|
|
370
|
+
const exportEntry = {
|
|
371
|
+
capability: z.string().describe("The capability whose rows these are — the purge step that erases them."),
|
|
372
|
+
summary: z.string().describe("What that capability's purge erases or anonymizes, in its own sentence."),
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
/** One capability's part of an export. */
|
|
376
|
+
const AdminUserExportEntry = z
|
|
377
|
+
.discriminatedUnion("state", [
|
|
378
|
+
z
|
|
379
|
+
.object({
|
|
380
|
+
...exportEntry,
|
|
381
|
+
state: z.literal("exported").describe("The capability answered."),
|
|
382
|
+
data: z
|
|
383
|
+
.record(z.string(), z.unknown())
|
|
384
|
+
.describe(
|
|
385
|
+
"What it holds about the account, in the shape that capability exports. `auth`'s is `AuthUserExport`.",
|
|
386
|
+
),
|
|
387
|
+
})
|
|
388
|
+
.describe("A capability's rows about the account."),
|
|
389
|
+
z
|
|
390
|
+
.object({
|
|
391
|
+
...exportEntry,
|
|
392
|
+
state: z
|
|
393
|
+
.literal("not_exported")
|
|
394
|
+
.describe("The capability erases rows about the account and does not say how to export them."),
|
|
395
|
+
})
|
|
396
|
+
.describe("A capability that holds rows it does not export. Ask its owner."),
|
|
397
|
+
z
|
|
398
|
+
.object({
|
|
399
|
+
...exportEntry,
|
|
400
|
+
state: z.literal("unavailable").describe("The capability's rows could not be read on this request."),
|
|
401
|
+
})
|
|
402
|
+
.describe("Nothing was established about this capability's rows. Deliberately empty — it is not 'none'."),
|
|
403
|
+
])
|
|
404
|
+
.describe("One capability's part of an export, behind a state, so an unread part cannot be taken for an empty one.");
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* `GET {base}/admin/users/:userId/export` (#622).
|
|
408
|
+
*
|
|
409
|
+
* Everything the kit holds about one account — the answer to an access request. One entry per composed
|
|
410
|
+
* capability that declares a purge contribution, in the order the purge runs them, each read on its own so
|
|
411
|
+
* one that will not read costs its own entry and not the document.
|
|
412
|
+
*/
|
|
413
|
+
export const AdminUserExportResponse = z
|
|
414
|
+
.object({
|
|
415
|
+
subject: z
|
|
416
|
+
.object({
|
|
417
|
+
type: z.literal("user").describe("The kind of subject: one person's account."),
|
|
418
|
+
id: z.string().describe("The account's id, as `pithy_auth_users.id` stores it."),
|
|
419
|
+
})
|
|
420
|
+
.describe("Who this export is about."),
|
|
421
|
+
exportedAt: z.iso.datetime().describe("When the export was read, ISO-8601."),
|
|
422
|
+
capabilities: z
|
|
423
|
+
.array(AdminUserExportEntry)
|
|
424
|
+
.describe("Every composed capability's part, in the order the purge erases them."),
|
|
425
|
+
})
|
|
426
|
+
.describe("Everything the kit holds about one account, from every composed capability, as one document.");
|
|
427
|
+
export type AdminUserExportResponse = z.output<typeof AdminUserExportResponse>;
|
|
428
|
+
|
|
201
429
|
/*
|
|
202
430
|
* The routes a signed-in person calls on their own account. These are not read across the management
|
|
203
431
|
* version boundary the admin schemas above are, but a client generated from the contract reads Workers on
|
|
@@ -251,3 +479,20 @@ export const MyDeviceRevokeResponse = z
|
|
|
251
479
|
.object({ revoked: RevokedCount })
|
|
252
480
|
.describe("How many of the device's sessions the revocation signed out. The device's row goes with them.");
|
|
253
481
|
export type MyDeviceRevokeResponse = z.output<typeof MyDeviceRevokeResponse>;
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* `DELETE {base}/account` (#622) — the signed-in person deleted their own account. Always soft, on the
|
|
485
|
+
* configured window. Their sessions end with it, this one included.
|
|
486
|
+
*/
|
|
487
|
+
export const AccountDeleteResponse = z
|
|
488
|
+
.object({
|
|
489
|
+
state: z.literal("deleted").describe("The account is deleted. This session and every other one has ended."),
|
|
490
|
+
purgeAfter: PurgeAfter,
|
|
491
|
+
mailed: z
|
|
492
|
+
.boolean()
|
|
493
|
+
.describe(
|
|
494
|
+
"Whether the deletion-scheduled mail, with the purge date and how to ask for the account back, was sent.",
|
|
495
|
+
),
|
|
496
|
+
})
|
|
497
|
+
.describe("The caller's own account, deleted: when its data will be erased, and whether they were mailed.");
|
|
498
|
+
export type AccountDeleteResponse = z.output<typeof AccountDeleteResponse>;
|
package/src/http/routes.ts
CHANGED
|
@@ -10,12 +10,15 @@ import { STORED_IMAGE_HEADERS, storedImageBytes } from "@pithy-sh/core/src/image
|
|
|
10
10
|
import { TURNSTILE_LOGIN_ACTION } from "@pithy-sh/turnstile/src/config/config";
|
|
11
11
|
import { turnstile } from "@pithy-sh/turnstile/src/http/middleware";
|
|
12
12
|
import type { Context, Hono } from "hono";
|
|
13
|
+
import { userSessionTokens } from "../admin/users";
|
|
13
14
|
import { correlation, emitDenied, emitDeviceRevoked, emitTokenRefresh, emitTokenReuseDetected } from "../audit/emit";
|
|
14
15
|
import type { AuthWiring } from "../capability";
|
|
15
16
|
import { authDatabase } from "../data/tables";
|
|
16
17
|
import { deleteDevice, deviceSessionTokens, listDevices } from "../device/registry";
|
|
17
18
|
import { noticedRefusal } from "../lifecycle/enforce";
|
|
19
|
+
import { lifecycleDeps } from "../lifecycle/request";
|
|
18
20
|
import { isLifecycleRefusal } from "../lifecycle/state";
|
|
21
|
+
import { deleteUser } from "../lifecycle/transitions";
|
|
19
22
|
import { PROFILE_IMAGE_PATH } from "../profile/profile";
|
|
20
23
|
import {
|
|
21
24
|
consumeSession,
|
|
@@ -28,12 +31,13 @@ import { registerAuthAdminRoutes } from "./adminRoutes";
|
|
|
28
31
|
import { guardErrorCallbackURL } from "./errorCallbackUrl";
|
|
29
32
|
import { apiErrorToPithy } from "./errors";
|
|
30
33
|
import { admitsRefusedAccount, lifecycleRedirect } from "./lifecycleGate";
|
|
31
|
-
import { requireAuth } from "./middleware";
|
|
34
|
+
import { accountHolder, requireAccountHolder, requireAuth } from "./middleware";
|
|
32
35
|
import { requireFreshAuthentication } from "./providerFreshness";
|
|
33
36
|
import { collapseProviderRefusal } from "./providerRefusal";
|
|
34
37
|
import { getAuthInstance, resolveDb } from "./resolve";
|
|
35
|
-
import { MyDeviceRevokeResponse, MyDevicesResponse, TokenRotateResponse } from "./responses";
|
|
36
|
-
import { RevokeDeviceBody } from "./schemas";
|
|
38
|
+
import { AccountDeleteResponse, MyDeviceRevokeResponse, MyDevicesResponse, TokenRotateResponse } from "./responses";
|
|
39
|
+
import { DeleteAccountBody, RevokeDeviceBody } from "./schemas";
|
|
40
|
+
import { accountDeletionView } from "./views";
|
|
37
41
|
|
|
38
42
|
type Ctx = Context<PithyHonoEnv>;
|
|
39
43
|
|
|
@@ -67,6 +71,7 @@ function db(c: Ctx, wiring: AuthWiring) {
|
|
|
67
71
|
* | `POST /token/rotate` | bearer/session | none — the credential only |
|
|
68
72
|
* | `GET /devices` | bearer/session | none |
|
|
69
73
|
* | `POST /devices/revoke` | bearer/session | json `RevokeDeviceBody` |
|
|
74
|
+
* | `DELETE /account` | bearer/session | json `DeleteAccountBody` |
|
|
70
75
|
* | `* /admin/*` | control-plane | see `./adminRoutes` |
|
|
71
76
|
*
|
|
72
77
|
* The catch-all takes NO validator, deliberately: `handleBetterAuth` hands Better Auth `c.req.raw`,
|
|
@@ -135,6 +140,25 @@ export function createAuthRoutes(wiring: AuthWiring): (app: Hono<PithyHonoEnv>)
|
|
|
135
140
|
(c) => revokeMyDevice(c, wiring, c.req.valid("json")),
|
|
136
141
|
);
|
|
137
142
|
|
|
143
|
+
// The signed-in person deletes their own account (#622) — always soft, on the configured window. The one
|
|
144
|
+
// route a suspended account still reaches: the app stores require that somebody can always leave, and a
|
|
145
|
+
// suspension is no reason to keep them. CSRF-guarded as a mutating route; the subject is the session's own,
|
|
146
|
+
// and nothing in the body can name another.
|
|
147
|
+
app.delete(
|
|
148
|
+
`${base}/account`,
|
|
149
|
+
describeRoute({
|
|
150
|
+
summary: "Delete the caller's own account. Always soft: restorable until the purge window closes.",
|
|
151
|
+
description:
|
|
152
|
+
"What the App Store and Google Play require of an app with accounts. A suspended account may still delete itself, with the session a sign-in carrying `x-pithy-intent: delete-account` gets it; a deleted one is refused with `auth/account_deleted`. Every session ends, this one included. The body must carry `confirm: true`.",
|
|
153
|
+
verification: ["bearer", "session"],
|
|
154
|
+
responses: { 200: AccountDeleteResponse },
|
|
155
|
+
}),
|
|
156
|
+
requireAccountHolder(),
|
|
157
|
+
csrf,
|
|
158
|
+
validate("json", DeleteAccountBody),
|
|
159
|
+
(c) => deleteMyAccount(c, wiring),
|
|
160
|
+
);
|
|
161
|
+
|
|
138
162
|
// **Changing which providers can sign you in requires a recent authentication — both directions.**
|
|
139
163
|
// Mounted explicitly ahead of the catch-all, or neither gate runs. `http/providerFreshness.ts`
|
|
140
164
|
// carries the argument: Better Auth guards the two unevenly, and its guard on the unlink side reads
|
|
@@ -502,6 +526,34 @@ async function listMyDevices(c: Ctx, wiring: AuthWiring): Promise<Response> {
|
|
|
502
526
|
return c.json({ devices: await listDevices(db(c, wiring), userId) });
|
|
503
527
|
}
|
|
504
528
|
|
|
529
|
+
/**
|
|
530
|
+
* Delete the caller's own account (#622): soft, on the configured window, audited as `auth/user_self_deleted`
|
|
531
|
+
* with them as the actor, and every session they hold ended after the columns are written — through Better
|
|
532
|
+
* Auth's adapter, so `onSessionRevoked` hears each. No reason: a person leaving owes nobody one.
|
|
533
|
+
*/
|
|
534
|
+
async function deleteMyAccount(c: Ctx, wiring: AuthWiring): Promise<Response> {
|
|
535
|
+
const holder = accountHolder(c);
|
|
536
|
+
if (!holder) throw new UnauthorizedError({ message: "Authentication required." });
|
|
537
|
+
const { ip, userAgent } = correlation(c.req.raw.headers);
|
|
538
|
+
const deps = lifecycleDeps(c, wiring, {
|
|
539
|
+
ip,
|
|
540
|
+
userAgent,
|
|
541
|
+
requestId: c.req.header("cf-ray"),
|
|
542
|
+
metadata: { sessionId: holder.sessionId, suspended: holder.suspended },
|
|
543
|
+
});
|
|
544
|
+
const result = await deleteUser(deps, {
|
|
545
|
+
userId: holder.userId,
|
|
546
|
+
actor: { type: "user", id: holder.userId },
|
|
547
|
+
reason: null,
|
|
548
|
+
});
|
|
549
|
+
const tokens = await userSessionTokens(db(c, wiring), holder.userId);
|
|
550
|
+
const ctx = await (await getAuthInstance(c, wiring)).$context;
|
|
551
|
+
for (const token of tokens) {
|
|
552
|
+
await ctx.internalAdapter.deleteSession(token);
|
|
553
|
+
}
|
|
554
|
+
return c.json(accountDeletionView(result) satisfies AccountDeleteResponse);
|
|
555
|
+
}
|
|
556
|
+
|
|
505
557
|
/** Revoke one of the authenticated user's devices: sign out its sessions, then drop the device row. */
|
|
506
558
|
async function revokeMyDevice(c: Ctx, wiring: AuthWiring, body: RevokeDeviceBody): Promise<Response> {
|
|
507
559
|
const userId = c.var.auth?.userId;
|
package/src/http/schemas.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
+
import { JsonDate } from "@pithy-sh/core/src/data/codecs";
|
|
4
5
|
import { MAX_PAGE_SIZE } from "@pithy-sh/core/src/data/cursor";
|
|
5
6
|
import { z } from "zod";
|
|
6
7
|
import { DevicePlatform } from "../data/device";
|
|
8
|
+
import { MAX_REASON } from "../lifecycle/reason";
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* The request schemas for the auth routes Pithy owns. Validation happens at the HTTP boundary
|
|
@@ -116,3 +118,111 @@ export const RevokeSessionBody = z
|
|
|
116
118
|
})
|
|
117
119
|
.describe("The body identifying which single session to revoke.");
|
|
118
120
|
export type RevokeSessionBody = z.output<typeof RevokeSessionBody>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Why an account's access is changing — required on both lifecycle routes (#621).
|
|
124
|
+
*
|
|
125
|
+
* Trimmed, then bounded by the same constant the transition enforces, so a reason the transition would refuse
|
|
126
|
+
* is a 400 here rather than a conflict later. Required rather than defaulted: a suspension nobody explained is
|
|
127
|
+
* a lockout the person cannot answer, and the trail would record nothing about why.
|
|
128
|
+
*/
|
|
129
|
+
const LifecycleReason = z
|
|
130
|
+
.string()
|
|
131
|
+
.trim()
|
|
132
|
+
.min(1)
|
|
133
|
+
.max(MAX_REASON)
|
|
134
|
+
.describe(
|
|
135
|
+
"Why, in a sentence written for the person. A suspension's reason is what every refused sign-in shows them.",
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
/** Whether the person is mailed. */
|
|
139
|
+
const Notify = z
|
|
140
|
+
.boolean()
|
|
141
|
+
.optional()
|
|
142
|
+
.describe(
|
|
143
|
+
"Whether to mail the person. Absent is true. The config can turn a lifecycle mail off for every call; this turns it off for one.",
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
/** The body of `POST /admin/users/:userId/suspend`. */
|
|
147
|
+
export const SuspendUserBody = z
|
|
148
|
+
.object({
|
|
149
|
+
reason: LifecycleReason,
|
|
150
|
+
until: JsonDate.optional().describe(
|
|
151
|
+
"When the suspension ends by itself, as an ISO-8601 timestamp. Must be in the future. Absent lasts until a reinstatement. Nothing is written when it passes.",
|
|
152
|
+
),
|
|
153
|
+
notify: Notify,
|
|
154
|
+
})
|
|
155
|
+
.describe(
|
|
156
|
+
"A suspension: why, until when, and whether to tell the person. Suspending a suspended account restates the reason and the end.",
|
|
157
|
+
);
|
|
158
|
+
export type SuspendUserBody = z.output<typeof SuspendUserBody>;
|
|
159
|
+
|
|
160
|
+
/** The body of `POST /admin/users/:userId/reinstate`. */
|
|
161
|
+
export const ReinstateUserBody = z
|
|
162
|
+
.object({ reason: LifecycleReason, notify: Notify })
|
|
163
|
+
.describe("A reinstatement: why, and whether to tell the person. It restores no session.");
|
|
164
|
+
export type ReinstateUserBody = z.output<typeof ReinstateUserBody>;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* How a deletion runs (#622). `soft` is the default and the only thing an omission reaches: the account is shut
|
|
168
|
+
* now and erased once the window closes, restorable until then. `hard` starts the purge at once, with no
|
|
169
|
+
* window, and is reached only by naming it — a typo is a 400, never either mode.
|
|
170
|
+
*/
|
|
171
|
+
export const DeletionMode = z
|
|
172
|
+
.enum(["soft", "hard"])
|
|
173
|
+
.describe(
|
|
174
|
+
"`soft` (the default): the account is shut now and its data erased once `retention.purgeAfterDays` have passed; it can be restored until then. `hard`: the purge starts now, with no window and nothing to restore.",
|
|
175
|
+
);
|
|
176
|
+
export type DeletionMode = z.output<typeof DeletionMode>;
|
|
177
|
+
|
|
178
|
+
/** The body of `DELETE /admin/users/:userId`. */
|
|
179
|
+
export const DeleteUserBody = z
|
|
180
|
+
.object({
|
|
181
|
+
mode: DeletionMode.default("soft").describe(
|
|
182
|
+
"`soft` unless named: the window, then the purge. `hard` purges now. Anything else is refused.",
|
|
183
|
+
),
|
|
184
|
+
reason: LifecycleReason,
|
|
185
|
+
notify: z
|
|
186
|
+
.boolean()
|
|
187
|
+
.optional()
|
|
188
|
+
.describe(
|
|
189
|
+
"Whether to mail the person. Absent is true. It silences the mail this call sends: the deletion-scheduled notice for `soft`, the deletion-complete notice for `hard`.",
|
|
190
|
+
),
|
|
191
|
+
})
|
|
192
|
+
.describe("A deletion: soft or hard, why, and whether to tell the person.");
|
|
193
|
+
export type DeleteUserBody = z.output<typeof DeleteUserBody>;
|
|
194
|
+
|
|
195
|
+
/** The body of `POST /admin/users/:userId/restore`. */
|
|
196
|
+
export const RestoreUserBody = z
|
|
197
|
+
.object({ reason: LifecycleReason })
|
|
198
|
+
.describe("A restoration inside the purge window: why. It restores no session; the person signs in again.");
|
|
199
|
+
export type RestoreUserBody = z.output<typeof RestoreUserBody>;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The query of `GET /admin/users/:userId/export`. A disclosure of everything the kit holds about one person
|
|
203
|
+
* says why, like every lifecycle call: the reason goes on the trail beside who asked.
|
|
204
|
+
*/
|
|
205
|
+
export const ExportUserQuery = z
|
|
206
|
+
.object({
|
|
207
|
+
reason: LifecycleReason.describe(
|
|
208
|
+
"Why this person's data is being exported — the access request it answers. Recorded on the audit trail.",
|
|
209
|
+
),
|
|
210
|
+
})
|
|
211
|
+
.describe("An export: why it is being made.");
|
|
212
|
+
export type ExportUserQuery = z.output<typeof ExportUserQuery>;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The body of `DELETE /account`, the signed-in person deleting their own account (#622).
|
|
216
|
+
*
|
|
217
|
+
* The confirmation is the literal `true`, so a client must say it on purpose: a stray `DELETE` with an empty
|
|
218
|
+
* body, or a form posting `"false"`, deletes nothing. There is no field naming an account — the subject is the
|
|
219
|
+
* session's own, always — and a key that tries is dropped.
|
|
220
|
+
*/
|
|
221
|
+
export const DeleteAccountBody = z
|
|
222
|
+
.object({
|
|
223
|
+
confirm: z
|
|
224
|
+
.literal(true)
|
|
225
|
+
.describe("Must be `true`. The person confirmed, in your app, that they want their account deleted."),
|
|
226
|
+
})
|
|
227
|
+
.describe("A self-service deletion: the person's own confirmation. Always soft, on the configured window.");
|
|
228
|
+
export type DeleteAccountBody = z.output<typeof DeleteAccountBody>;
|
package/src/http/views.ts
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { PurgeExportEntry } from "@pithy-sh/core/src/capability/purge";
|
|
5
|
+
import type { Account, Session, User } from "../data/betterAuth";
|
|
5
6
|
import type { Device } from "../data/device";
|
|
6
|
-
import type {
|
|
7
|
+
import type { UserLifecycleEvent } from "../data/userLifecycle";
|
|
8
|
+
import type {
|
|
9
|
+
DeleteTransition,
|
|
10
|
+
DeletionMode,
|
|
11
|
+
LifecycleTransition,
|
|
12
|
+
RestoreTransition,
|
|
13
|
+
SuspendTransition,
|
|
14
|
+
} from "../lifecycle/transitions";
|
|
15
|
+
import type {
|
|
16
|
+
AccountDeleteResponse,
|
|
17
|
+
AdminDeviceView,
|
|
18
|
+
AdminSessionView,
|
|
19
|
+
AdminUserDeleteResponse,
|
|
20
|
+
AdminUserExportResponse,
|
|
21
|
+
AdminUserReinstateResponse,
|
|
22
|
+
AdminUserRestoreResponse,
|
|
23
|
+
AdminUserSuspendResponse,
|
|
24
|
+
AdminUserView,
|
|
25
|
+
AuthUserExport,
|
|
26
|
+
} from "./responses";
|
|
7
27
|
|
|
8
28
|
/**
|
|
9
29
|
* The admin projections — what a management client is shown of a user, a session, and a device.
|
|
@@ -91,3 +111,128 @@ export function deviceView(device: Device): AdminDeviceView {
|
|
|
91
111
|
createdAt: device.createdAt.toISOString(),
|
|
92
112
|
};
|
|
93
113
|
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The suspension projection (#621): the suspension the transition left in force, and the sessions the route
|
|
117
|
+
* revoked after it. Dates cross as ISO-8601, like every other response here.
|
|
118
|
+
*/
|
|
119
|
+
export function suspensionView(
|
|
120
|
+
userId: string,
|
|
121
|
+
result: SuspendTransition,
|
|
122
|
+
sessionsRevoked: number,
|
|
123
|
+
): AdminUserSuspendResponse {
|
|
124
|
+
return {
|
|
125
|
+
userId,
|
|
126
|
+
state: "suspended",
|
|
127
|
+
outcome: result.updated ? "updated" : "suspended",
|
|
128
|
+
suspendedAt: result.suspendedAt.toISOString(),
|
|
129
|
+
suspendedUntil: result.suspendedUntil?.toISOString() ?? null,
|
|
130
|
+
sessionsRevoked,
|
|
131
|
+
mailed: result.mailed,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The reinstatement projection (#621). A call that found no suspension in force is `unchanged`. */
|
|
136
|
+
export function reinstatementView(userId: string, result: LifecycleTransition): AdminUserReinstateResponse {
|
|
137
|
+
return {
|
|
138
|
+
userId,
|
|
139
|
+
state: "active",
|
|
140
|
+
outcome: result.changed ? "reinstated" : "unchanged",
|
|
141
|
+
mailed: result.mailed,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** What became of a deletion's purge: due later, started by the call, or due with nothing bound to start it. */
|
|
146
|
+
export type PurgeDisposition = AdminUserDeleteResponse["purge"];
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The deletion projection (#622): the deletion the transition left in force, the sessions the route revoked
|
|
150
|
+
* after it, and what became of the purge.
|
|
151
|
+
*/
|
|
152
|
+
export function deletionView(
|
|
153
|
+
userId: string,
|
|
154
|
+
mode: DeletionMode,
|
|
155
|
+
result: DeleteTransition,
|
|
156
|
+
purge: PurgeDisposition,
|
|
157
|
+
sessionsRevoked: number,
|
|
158
|
+
): AdminUserDeleteResponse {
|
|
159
|
+
return {
|
|
160
|
+
userId,
|
|
161
|
+
state: "deleted",
|
|
162
|
+
mode,
|
|
163
|
+
outcome: result.outcome,
|
|
164
|
+
deletedAt: result.deletedAt.toISOString(),
|
|
165
|
+
purgeAfter: result.purgeAfter.toISOString(),
|
|
166
|
+
purge,
|
|
167
|
+
sessionsRevoked,
|
|
168
|
+
mailed: result.mailed,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The restoration projection (#622). A call that found the account not deleted is `unchanged`. */
|
|
173
|
+
export function restorationView(userId: string, result: RestoreTransition): AdminUserRestoreResponse {
|
|
174
|
+
return { userId, state: result.state, outcome: result.changed ? "restored" : "unchanged" };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The self-service deletion projection (#622). */
|
|
178
|
+
export function accountDeletionView(result: DeleteTransition): AccountDeleteResponse {
|
|
179
|
+
return { state: "deleted", purgeAfter: result.purgeAfter.toISOString(), mailed: result.mailed };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** A date as the wire carries it, or null. */
|
|
183
|
+
function iso(date: Date | null | undefined): string | null {
|
|
184
|
+
return date ? date.toISOString() : null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* What auth holds about one account, as its export carries it (#622) — the person's own data, projected through
|
|
189
|
+
* the same views a support pane sees, so a session token, a provider token and a push token are absent here by
|
|
190
|
+
* the same construction that keeps them out of every other response. The operator who made a transition is
|
|
191
|
+
* theirs to disclose, not the person's, so the history carries the kind of actor and not its id.
|
|
192
|
+
*/
|
|
193
|
+
export function authUserExportView(input: {
|
|
194
|
+
user: User;
|
|
195
|
+
sessions: readonly Session[];
|
|
196
|
+
accounts: readonly Pick<Account, "providerId" | "createdAt">[];
|
|
197
|
+
devices: readonly Device[];
|
|
198
|
+
history: readonly UserLifecycleEvent[];
|
|
199
|
+
plugins?: Record<string, Record<string, unknown>[]>;
|
|
200
|
+
}): AuthUserExport {
|
|
201
|
+
const { user } = input;
|
|
202
|
+
return {
|
|
203
|
+
user: {
|
|
204
|
+
...userView(user),
|
|
205
|
+
suspendedAt: iso(user.suspendedAt),
|
|
206
|
+
suspendedUntil: iso(user.suspendedUntil),
|
|
207
|
+
deletedAt: iso(user.deletedAt),
|
|
208
|
+
purgeAfter: iso(user.purgeAfter),
|
|
209
|
+
},
|
|
210
|
+
sessions: input.sessions.map(sessionView),
|
|
211
|
+
providers: input.accounts.map((account) => ({
|
|
212
|
+
providerId: account.providerId,
|
|
213
|
+
createdAt: account.createdAt.toISOString(),
|
|
214
|
+
})),
|
|
215
|
+
devices: input.devices.map(deviceView),
|
|
216
|
+
history: input.history.map((event) => ({
|
|
217
|
+
action: event.action,
|
|
218
|
+
actorType: event.actorType,
|
|
219
|
+
reason: event.reason,
|
|
220
|
+
suspendedUntil: iso(event.suspendedUntil),
|
|
221
|
+
createdAt: event.createdAt.toISOString(),
|
|
222
|
+
})),
|
|
223
|
+
plugins: input.plugins ?? {},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** The export document (#622): who it is about, when it was read, and every capability's part. */
|
|
228
|
+
export function exportView(
|
|
229
|
+
userId: string,
|
|
230
|
+
exportedAt: Date,
|
|
231
|
+
entries: readonly PurgeExportEntry[],
|
|
232
|
+
): AdminUserExportResponse {
|
|
233
|
+
return {
|
|
234
|
+
subject: { type: "user", id: userId },
|
|
235
|
+
exportedAt: exportedAt.toISOString(),
|
|
236
|
+
capabilities: entries.map((entry) => ({ ...entry })),
|
|
237
|
+
};
|
|
238
|
+
}
|
package/src/instance/auth.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { KIT_SESSION_FIELDS, KIT_USER_FIELDS } from "../data/kitFields";
|
|
|
17
17
|
import type { AuthDatabase } from "../data/tables";
|
|
18
18
|
import { parseDeviceMeta, registerDevice } from "../device/registry";
|
|
19
19
|
import { PROVIDER_CHANGE_FRESH_AGE_SECONDS } from "../http/providerFreshness";
|
|
20
|
-
import { lifecycleRefusalFor } from "../lifecycle/enforce";
|
|
20
|
+
import { admitsDeletionSignIn, lifecycleRefusalFor } from "../lifecycle/enforce";
|
|
21
21
|
import { refuseUnsafeProfile, sanitizeProfile } from "../profile/profile";
|
|
22
22
|
import { defaultGithubUserInfo, type GithubUserInfoResolver } from "./githubUserInfo";
|
|
23
23
|
import { microsoftProfileToUser } from "./microsoftEmail";
|
|
@@ -522,8 +522,13 @@ export function makeAuth<const Plugins extends readonly BetterAuthPlugin[]>(deps
|
|
|
522
522
|
// so this one check is what makes a suspension hold at every door, and the reason it is not
|
|
523
523
|
// written once per endpoint. The row is read rather than trusted from the caller: nothing
|
|
524
524
|
// that arrives with a sign-in may say whether its own account is suspended.
|
|
525
|
+
//
|
|
526
|
+
// **One exception: a suspended account that signs in to delete itself (#622).** The app stores
|
|
527
|
+
// require that a person can always leave, and a suspension has already revoked every session the
|
|
528
|
+
// account held. The session this admits is still a suspended account's, so every request it makes
|
|
529
|
+
// is refused except `DELETE /auth/account` — see `admitsDeletionSignIn`.
|
|
525
530
|
const refusal = await lifecycleRefusalFor(deps.db, session.userId, null, new Date());
|
|
526
|
-
if (refusal) refuseSession(refusal, ctx);
|
|
531
|
+
if (refusal && !admitsDeletionSignIn(refusal, ctx?.headers)) refuseSession(refusal, ctx);
|
|
527
532
|
// **`undefined` and `null` are different answers here, and collapsing them is a hole.**
|
|
528
533
|
// Absent means nobody supplied one, which is a sign-in: stamp it. Present-and-null is a
|
|
529
534
|
// rotation of a session written before the column existed, and it must stay null so the gate
|