@pithy-sh/auth 0.9.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 +8 -2
- package/dist/admin/users.js +1 -1
- package/dist/audit/actions.d.ts +40 -0
- package/dist/audit/actions.d.ts.map +1 -1
- package/dist/audit/actions.js +41 -1
- package/dist/audit/emit.d.ts +2 -0
- package/dist/audit/emit.d.ts.map +1 -1
- package/dist/audit/emit.js +2 -2
- package/dist/capability.d.ts +45 -1
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +40 -5
- package/dist/client/lifecycle.d.ts +19 -0
- package/dist/client/lifecycle.d.ts.map +1 -0
- package/dist/client/lifecycle.js +25 -0
- package/dist/client/projection.d.ts +4 -0
- package/dist/client/projection.d.ts.map +1 -1
- package/dist/data/betterAuth.d.ts +4 -0
- package/dist/data/betterAuth.d.ts.map +1 -1
- package/dist/data/betterAuth.js +6 -2
- package/dist/data/kitFields.d.ts +20 -25
- package/dist/data/kitFields.d.ts.map +1 -1
- package/dist/data/kitFields.js +28 -32
- package/dist/data/tables.d.ts +29 -2
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/tables.js +5 -3
- package/dist/data/userLifecycle.d.ts +62 -0
- package/dist/data/userLifecycle.d.ts.map +1 -0
- package/dist/data/userLifecycle.js +51 -0
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +270 -5
- package/dist/http/guards.d.ts +24 -1
- package/dist/http/guards.d.ts.map +1 -1
- package/dist/http/guards.js +59 -3
- package/dist/http/lifecycleGate.d.ts +18 -0
- package/dist/http/lifecycleGate.d.ts.map +1 -0
- package/dist/http/lifecycleGate.js +75 -0
- package/dist/http/middleware.d.ts +30 -1
- package/dist/http/middleware.d.ts.map +1 -1
- package/dist/http/middleware.js +89 -7
- package/dist/http/providerRefusal.d.ts.map +1 -1
- package/dist/http/providerRefusal.js +8 -0
- package/dist/http/resolve.d.ts.map +1 -1
- package/dist/http/resolve.js +7 -4
- 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 +65 -4
- 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 +55 -3
- package/dist/instance/auth.d.ts.map +1 -1
- package/dist/instance/auth.js +53 -2
- package/dist/instance/microsoftEmail.d.ts +70 -0
- package/dist/instance/microsoftEmail.d.ts.map +1 -0
- package/dist/instance/microsoftEmail.js +96 -0
- package/dist/instance/providerSignInGate.d.ts +7 -6
- package/dist/instance/providerSignInGate.d.ts.map +1 -1
- package/dist/instance/providerSignInGate.js +7 -6
- package/dist/instance/providers.d.ts +7 -5
- package/dist/instance/providers.d.ts.map +1 -1
- package/dist/instance/providers.js +5 -3
- package/dist/instance/secrets.d.ts +64 -3
- package/dist/instance/secrets.d.ts.map +1 -1
- package/dist/instance/secrets.js +44 -5
- 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 +75 -0
- package/dist/lifecycle/enforce.d.ts.map +1 -0
- package/dist/lifecycle/enforce.js +111 -0
- package/dist/lifecycle/hooks.d.ts +53 -0
- package/dist/lifecycle/hooks.d.ts.map +1 -0
- package/dist/lifecycle/hooks.js +2 -0
- 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 +18 -0
- package/dist/lifecycle/request.d.ts.map +1 -0
- package/dist/lifecycle/request.js +31 -0
- package/dist/lifecycle/state.d.ts +64 -0
- package/dist/lifecycle/state.d.ts.map +1 -0
- package/dist/lifecycle/state.js +90 -0
- package/dist/lifecycle/transitions.d.ts +272 -0
- package/dist/lifecycle/transitions.d.ts.map +1 -0
- package/dist/lifecycle/transitions.js +623 -0
- package/dist/migrations/0004_user_lifecycle.d.ts +28 -0
- package/dist/migrations/0004_user_lifecycle.d.ts.map +1 -0
- package/dist/migrations/0004_user_lifecycle.js +47 -0
- 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 +3 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +6 -2
- package/dist/peer.d.ts +4 -0
- package/dist/peer.d.ts.map +1 -1
- 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/test-utils/liveApp.d.ts +21 -0
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +1 -0
- package/dist/test-utils/scopedBackend.d.ts +21 -0
- package/dist/test-utils/scopedBackend.d.ts.map +1 -1
- package/dist/test-utils/scopedBackend.js +7 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.d.ts.map +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/account-lifecycle.md +217 -0
- package/docs/apple-signin.md +7 -1
- package/docs/facebook-oauth.md +7 -1
- package/docs/github-oauth.md +7 -1
- package/docs/google-oauth.md +7 -1
- package/docs/microsoft-oauth.md +177 -0
- package/package.json +5 -5
- package/pithy.manifest.json +17 -3
- package/src/audit/actions.ts +42 -0
- package/src/audit/emit.ts +4 -2
- package/src/capability.ts +170 -52
- package/src/client/lifecycle.ts +27 -0
- package/src/client/projection.ts +4 -0
- package/src/data/betterAuth.ts +21 -1
- package/src/data/kitFields.ts +27 -0
- package/src/data/tables.ts +4 -2
- package/src/data/userLifecycle.ts +83 -0
- package/src/http/adminRoutes.ts +398 -2
- package/src/http/guards.ts +61 -1
- package/src/http/lifecycleGate.ts +78 -0
- package/src/http/middleware.ts +104 -2
- package/src/http/providerRefusal.ts +10 -0
- package/src/http/resolve.ts +8 -3
- package/src/http/responses.ts +245 -0
- package/src/http/routes.ts +93 -4
- package/src/http/schemas.ts +110 -0
- package/src/http/views.ts +147 -2
- package/src/instance/auth.ts +74 -2
- package/src/instance/microsoftEmail.ts +111 -0
- package/src/instance/providerSignInGate.ts +7 -6
- package/src/instance/providers.ts +8 -4
- package/src/instance/secrets.ts +59 -5
- package/src/lifecycle/audited.ts +104 -0
- package/src/lifecycle/enforce.ts +139 -0
- package/src/lifecycle/hooks.ts +54 -0
- package/src/lifecycle/reason.ts +11 -0
- package/src/lifecycle/request.ts +39 -0
- package/src/lifecycle/state.ts +101 -0
- package/src/lifecycle/transitions.ts +872 -0
- package/src/migrations/0004_user_lifecycle.ts +68 -0
- package/src/migrations/0005_purge_once.ts +42 -0
- package/src/migrations/pluginTables.ts +19 -1
- package/src/migrations/set.ts +5 -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/test-utils/liveApp.ts +2 -1
- package/src/test-utils/scopedBackend.ts +2 -1
- package/src/version.generated.ts +1 -1
package/src/instance/secrets.ts
CHANGED
|
@@ -26,12 +26,16 @@ import type { SessionSecretVersions } from "./sessionSecrets";
|
|
|
26
26
|
* Read only when the provider is enabled; rotated in the Meta app dashboard, not on our schedule.
|
|
27
27
|
* - `auth-github-credentials` — the GitHub OAuth app client id and secret, as a typed JSON value.
|
|
28
28
|
* Read only when the provider is enabled; rotated in GitHub Developer settings, not on our schedule.
|
|
29
|
+
* - `auth-microsoft-credentials` — the Microsoft Entra ID app registration's client id, client secret,
|
|
30
|
+
* and tenant, as a typed JSON value. The tenant rides inside because it means nothing apart from the
|
|
31
|
+
* registration it belongs to. Rotatable: an Entra client secret expires (24 months at most).
|
|
29
32
|
*/
|
|
30
33
|
export const AUTH_SESSION_SECRET = "auth-session-secret";
|
|
31
34
|
export const AUTH_GOOGLE_CREDENTIALS = "auth-google-credentials";
|
|
32
35
|
export const AUTH_APPLE_CREDENTIALS = "auth-apple-credentials";
|
|
33
36
|
export const AUTH_FACEBOOK_CREDENTIALS = "auth-facebook-credentials";
|
|
34
37
|
export const AUTH_GITHUB_CREDENTIALS = "auth-github-credentials";
|
|
38
|
+
export const AUTH_MICROSOFT_CREDENTIALS = "auth-microsoft-credentials";
|
|
35
39
|
|
|
36
40
|
/**
|
|
37
41
|
* The JWKS private keys, as `auth-session-secret`'s overlap names them (#602).
|
|
@@ -145,18 +149,52 @@ export const GithubOAuthCredentials = z
|
|
|
145
149
|
.describe("A GitHub OAuth credential pair (`clientId` + `clientSecret`) for one environment.");
|
|
146
150
|
export type GithubOAuthCredentials = z.infer<typeof GithubOAuthCredentials>;
|
|
147
151
|
|
|
152
|
+
/**
|
|
153
|
+
* The Microsoft Entra ID credentials, stored as one typed JSON secret.
|
|
154
|
+
*
|
|
155
|
+
* **`tenantId` is required and may not be empty.** Better Auth builds its endpoints from
|
|
156
|
+
* `options.tenantId || "common"`, so an empty string would not fail: it would quietly open a
|
|
157
|
+
* single-tenant app to every Entra tenant and every personal account.
|
|
158
|
+
*/
|
|
159
|
+
export const MicrosoftOAuthCredentials = z
|
|
160
|
+
.object({
|
|
161
|
+
clientId: z
|
|
162
|
+
.string()
|
|
163
|
+
.meta({ multiline: false })
|
|
164
|
+
.describe(
|
|
165
|
+
"The Application (client) ID of the Entra ID app registration for this environment. Not secret on its own, but stored with the secret so the set is atomic.",
|
|
166
|
+
),
|
|
167
|
+
clientSecret: z
|
|
168
|
+
.string()
|
|
169
|
+
.meta({ multiline: false })
|
|
170
|
+
.describe(
|
|
171
|
+
"A client secret value from the same app registration. Expires (24 months at most), so rotate it on schedule. Never committed, never an env literal.",
|
|
172
|
+
),
|
|
173
|
+
tenantId: z
|
|
174
|
+
.string()
|
|
175
|
+
.min(1)
|
|
176
|
+
.meta({ multiline: false })
|
|
177
|
+
.describe(
|
|
178
|
+
"Who may sign in: a directory (tenant) ID for one organization, `organizations` for any work or school account, `consumers` for personal accounts only, or `common` for both.",
|
|
179
|
+
),
|
|
180
|
+
})
|
|
181
|
+
.describe("A Microsoft Entra ID credential set (`clientId` + `clientSecret` + `tenantId`) for one environment.");
|
|
182
|
+
export type MicrosoftOAuthCredentials = z.infer<typeof MicrosoftOAuthCredentials>;
|
|
183
|
+
|
|
148
184
|
/**
|
|
149
185
|
* Where a human goes for each OAuth credential pair, and where the same human rotates it.
|
|
150
186
|
*
|
|
151
187
|
* **The settings page, not the product homepage.** The point is to end a search, not to start one — and
|
|
152
|
-
* these
|
|
153
|
-
* can offer. Named constants because origin and rotation are the same page for all
|
|
188
|
+
* these five are the case with no command and no possible one, so the link is the entire remedy the kit
|
|
189
|
+
* can offer. Named constants because origin and rotation are the same page for all five, and two copies
|
|
154
190
|
* of a URL is one that goes stale.
|
|
155
191
|
*/
|
|
156
192
|
const GOOGLE_CREDENTIALS_PAGE = "https://console.cloud.google.com/apis/credentials";
|
|
157
193
|
const APPLE_KEYS_PAGE = "https://developer.apple.com/account/resources/authkeys/list";
|
|
158
194
|
const FACEBOOK_APPS_PAGE = "https://developers.facebook.com/apps/";
|
|
159
195
|
const GITHUB_OAUTH_APPS_PAGE = "https://github.com/settings/developers";
|
|
196
|
+
const MICROSOFT_APP_REGISTRATIONS_PAGE =
|
|
197
|
+
"https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade";
|
|
160
198
|
|
|
161
199
|
export const authSecretsRegistry = defineSecretRegistry({
|
|
162
200
|
// `devValue` is the whole difference between an app that runs after `pithy add auth` and one that
|
|
@@ -176,7 +214,7 @@ export const authSecretsRegistry = defineSecretRegistry({
|
|
|
176
214
|
// its own from the configured `sessionExpiresIn`; this is what a module reading the secret sees.
|
|
177
215
|
overlap: { days: 7, minimumDays: 7, reencrypt: [AUTH_JWKS_DEPENDENT] },
|
|
178
216
|
},
|
|
179
|
-
// The
|
|
217
|
+
// The five below are `obtained` and rotate `manual`, and each names the page rather than the product.
|
|
180
218
|
// An adopter searching Google's console for which of four credential types "client secret" means is the
|
|
181
219
|
// gap this closes — and nothing will ever mint one, so saying where is the whole of what the kit can do.
|
|
182
220
|
[AUTH_GOOGLE_CREDENTIALS]: {
|
|
@@ -215,6 +253,15 @@ export const authSecretsRegistry = defineSecretRegistry({
|
|
|
215
253
|
origin: { kind: "obtained", issuer: "github", documentation: GITHUB_OAUTH_APPS_PAGE },
|
|
216
254
|
rotation: { kind: "manual", issuer: "github", documentation: GITHUB_OAUTH_APPS_PAGE },
|
|
217
255
|
},
|
|
256
|
+
[AUTH_MICROSOFT_CREDENTIALS]: {
|
|
257
|
+
backend: "d1",
|
|
258
|
+
scope: "environment",
|
|
259
|
+
rotatable: true,
|
|
260
|
+
valueType: "json",
|
|
261
|
+
schema: MicrosoftOAuthCredentials,
|
|
262
|
+
origin: { kind: "obtained", issuer: "microsoft", documentation: MICROSOFT_APP_REGISTRATIONS_PAGE },
|
|
263
|
+
rotation: { kind: "manual", issuer: "microsoft", documentation: MICROSOFT_APP_REGISTRATIONS_PAGE },
|
|
264
|
+
},
|
|
218
265
|
});
|
|
219
266
|
|
|
220
267
|
/**
|
|
@@ -272,15 +319,16 @@ const PROVIDER_CREDENTIALS = [
|
|
|
272
319
|
["apple", AUTH_APPLE_CREDENTIALS],
|
|
273
320
|
["facebook", AUTH_FACEBOOK_CREDENTIALS],
|
|
274
321
|
["github", AUTH_GITHUB_CREDENTIALS],
|
|
322
|
+
["microsoft", AUTH_MICROSOFT_CREDENTIALS],
|
|
275
323
|
] as const;
|
|
276
324
|
|
|
277
|
-
/** The
|
|
325
|
+
/** The five toggles this reads off the resolved `AuthConfig` — nothing else about it is its business. */
|
|
278
326
|
export type AuthProviderToggles = Record<(typeof PROVIDER_CREDENTIALS)[number][0], { enabled: boolean }>;
|
|
279
327
|
|
|
280
328
|
/**
|
|
281
329
|
* **The provider credentials this composition cannot reach**, as the `inapplicableSecrets` contribution.
|
|
282
330
|
*
|
|
283
|
-
* Auth declares
|
|
331
|
+
* Auth declares five credentials whether or not a project runs five providers, so a project on Google
|
|
284
332
|
* and GitHub carries two secrets nothing will ever read. `pithy doctor` asked for them every run under
|
|
285
333
|
* *"fine to leave until you need it"* — softening, not silence, and "until you need it" is wrong about a
|
|
286
334
|
* provider the configuration has not enabled.
|
|
@@ -339,3 +387,9 @@ export async function resolveGithubCredentials(env: SecretsStoreEnv): Promise<Gi
|
|
|
339
387
|
const secrets = await sharedSecretsStore(env, authSecretsRegistry);
|
|
340
388
|
return secrets.get(AUTH_GITHUB_CREDENTIALS);
|
|
341
389
|
}
|
|
390
|
+
|
|
391
|
+
/** Resolve the Microsoft Entra ID credentials for this invocation (only call when Microsoft is enabled). */
|
|
392
|
+
export async function resolveMicrosoftCredentials(env: SecretsStoreEnv): Promise<MicrosoftOAuthCredentials> {
|
|
393
|
+
const secrets = await sharedSecretsStore(env, authSecretsRegistry);
|
|
394
|
+
return secrets.get(AUTH_MICROSOFT_CREDENTIALS);
|
|
395
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { AuditEmit } from "@pithy-sh/core/src/audit/recorder";
|
|
5
|
+
import { PithyError } from "@pithy-sh/core/src/error/pithyError";
|
|
6
|
+
import { emitControlPlaneAction } from "../audit/emit";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Every control-plane lifecycle call is audited, including the ones that changed nothing (#621).
|
|
10
|
+
*
|
|
11
|
+
* A transition that moves the account writes its own audit event, beside the history row, in
|
|
12
|
+
* `./transitions.ts`. That leaves two kinds of call with no event, and both matter to somebody reading the
|
|
13
|
+
* trail after an incident: **a refusal** — an unknown account, a deleted one, an end in the past — which says
|
|
14
|
+
* a credential was trying, and **a call that found the account already where it asked to put it**, which
|
|
15
|
+
* says somebody pressed the button. This records both, under the same action as the transition, so one
|
|
16
|
+
* filter finds every attempt: a refusal is `denied` (or `failure` for a fault) with the code, and a no-op is
|
|
17
|
+
* a `success` with `changed: false`. A refusal is still thrown, unchanged.
|
|
18
|
+
*
|
|
19
|
+
* A body the route's validator refuses never reaches the call, so the route records it with
|
|
20
|
+
* {@link recordLifecycleRefusal}, on the same event, before the 400 is thrown.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** Who called, about whom, and why — what every lifecycle audit event carries. */
|
|
24
|
+
export interface LifecycleCall {
|
|
25
|
+
/** The audit action the transition writes when it moves the account. */
|
|
26
|
+
readonly action: string;
|
|
27
|
+
/** The management client's verified `sub`: which person acted. */
|
|
28
|
+
readonly subject: string;
|
|
29
|
+
/** The connection the call came through. */
|
|
30
|
+
readonly connectionId: string;
|
|
31
|
+
/** The account acted on. */
|
|
32
|
+
readonly userId: string;
|
|
33
|
+
/** The reason the caller gave — `null` for a refused body that carried none. */
|
|
34
|
+
readonly reason: string | null;
|
|
35
|
+
/** The request's correlation. */
|
|
36
|
+
readonly ip?: string | undefined;
|
|
37
|
+
readonly userAgent?: string | undefined;
|
|
38
|
+
readonly requestId?: string | undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The public code of a thrown error, or `core/internal` for anything that is not a `PithyError`. */
|
|
42
|
+
function codeOf(error: unknown): string {
|
|
43
|
+
return error instanceof PithyError ? error.payload.code : "core/internal";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A refusal this Worker made on purpose is `denied`; a fault, a 5xx or a throw that is not ours, `failure`. */
|
|
47
|
+
function outcomeOf(error: unknown): "denied" | "failure" {
|
|
48
|
+
return error instanceof PithyError && error.payload.status < 500 ? "denied" : "failure";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The event every lifecycle audit record shares, before its outcome and metadata. */
|
|
52
|
+
function eventOf(call: LifecycleCall) {
|
|
53
|
+
return {
|
|
54
|
+
action: call.action,
|
|
55
|
+
subject: call.subject,
|
|
56
|
+
connectionId: call.connectionId,
|
|
57
|
+
resourceType: "user",
|
|
58
|
+
resourceId: call.userId,
|
|
59
|
+
ip: call.ip,
|
|
60
|
+
userAgent: call.userAgent,
|
|
61
|
+
requestId: call.requestId,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Record one refused lifecycle call — `denied` with its code, or `failure` for a fault. `code` names the
|
|
67
|
+
* refusal when the thrown error carries none of its own, as a body Hono could not parse does not.
|
|
68
|
+
*/
|
|
69
|
+
export async function recordLifecycleRefusal(
|
|
70
|
+
emit: AuditEmit,
|
|
71
|
+
call: LifecycleCall,
|
|
72
|
+
error: unknown,
|
|
73
|
+
fallback?: { code: string; outcome: "denied" | "failure" },
|
|
74
|
+
): Promise<void> {
|
|
75
|
+
const ours = error instanceof PithyError;
|
|
76
|
+
await emitControlPlaneAction(emit, {
|
|
77
|
+
...eventOf(call),
|
|
78
|
+
outcome: ours || !fallback ? outcomeOf(error) : fallback.outcome,
|
|
79
|
+
metadata: { reason: call.reason, changed: false, code: ours || !fallback ? codeOf(error) : fallback.code },
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Run one lifecycle call and audit whatever the transition did not. `unchanged` says whether a result is a
|
|
85
|
+
* call that changed nothing; the event for a call that did change something is the transition's own.
|
|
86
|
+
*/
|
|
87
|
+
export async function auditedLifecycleCall<T>(
|
|
88
|
+
emit: AuditEmit,
|
|
89
|
+
call: LifecycleCall,
|
|
90
|
+
run: () => Promise<T>,
|
|
91
|
+
unchanged: (result: T) => boolean,
|
|
92
|
+
): Promise<T> {
|
|
93
|
+
let result: T;
|
|
94
|
+
try {
|
|
95
|
+
result = await run();
|
|
96
|
+
} catch (error) {
|
|
97
|
+
await recordLifecycleRefusal(emit, call, error);
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
if (unchanged(result)) {
|
|
101
|
+
await emitControlPlaneAction(emit, { ...eventOf(call), metadata: { reason: call.reason, changed: false } });
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { PithyError } from "@pithy-sh/core/src/error/pithyError";
|
|
5
|
+
import type { AuthDatabase } from "../data/tables";
|
|
6
|
+
import { accountStanding, LifecycleColumns, lifecycleRefusal } from "./state";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The reads enforcement needs, and the one place a refusal is remembered for the rest of a request.
|
|
10
|
+
*
|
|
11
|
+
* ## Where an account is refused
|
|
12
|
+
*
|
|
13
|
+
* - **Every request** — the session middleware reads the state off the user Better Auth resolved for the
|
|
14
|
+
* session, which carries the columns, so the check costs no query. A refused account gets no
|
|
15
|
+
* `AuthContext`, so every `requireAuth()` in the kit refuses it whoever wrote the guard; this capability's
|
|
16
|
+
* own `requireAuth()` raises the refusal itself, with its code, rather than a 401.
|
|
17
|
+
* - **Every sign-in and every token refresh** — `session.create.before` in `../instance/auth.ts`. Every way
|
|
18
|
+
* a session comes into being goes through `createSession`, so one hook covers magic link, OTP, every
|
|
19
|
+
* social callback and `/token/rotate` alike.
|
|
20
|
+
* - **Better Auth's own endpoints that act as the session's holder** — `/token`, `/get-session`,
|
|
21
|
+
* `/update-user` and the rest — refused in `handleBetterAuth` from the middleware's verdict, because
|
|
22
|
+
* Better Auth resolves its own session there and never asks this capability.
|
|
23
|
+
*
|
|
24
|
+
* The reason for a suspension is the one read only a refused request pays for: it lives in
|
|
25
|
+
* `pithy_auth_user_lifecycle`, not on the user row, so an account in good standing never costs a lookup.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** The reason given for the suspension in force — the newest `suspended` row — or null when none was written. */
|
|
29
|
+
export async function suspensionReason(db: AuthDatabase, userId: string): Promise<string | null> {
|
|
30
|
+
const row = await db
|
|
31
|
+
.selectFrom("pithyAuthUserLifecycle")
|
|
32
|
+
.select("reason")
|
|
33
|
+
.where("userId", "=", userId)
|
|
34
|
+
.where("action", "=", "suspended")
|
|
35
|
+
.orderBy("id", "desc")
|
|
36
|
+
.limit(1)
|
|
37
|
+
.executeTakeFirst();
|
|
38
|
+
const reason = row?.reason?.trim();
|
|
39
|
+
return reason ? reason : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** An account's lifecycle columns, read from its row, or `null` when there is no such account. */
|
|
43
|
+
export async function readLifecycleColumns(db: AuthDatabase, userId: string): Promise<LifecycleColumns | null> {
|
|
44
|
+
const row = await db
|
|
45
|
+
.selectFrom("pithyAuthUsers")
|
|
46
|
+
.select(["suspendedAt", "suspendedUntil", "deletedAt", "purgeAfter"])
|
|
47
|
+
.where("id", "=", userId)
|
|
48
|
+
.executeTakeFirst();
|
|
49
|
+
return row ? LifecycleColumns.parse(row) : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The refusal for this account at `now`, or `null` when it may act.
|
|
54
|
+
*
|
|
55
|
+
* `columns` is what the caller already holds — the session's user object, a row it read. Absent, the row is
|
|
56
|
+
* read here, which is the sign-in path: a session about to be created has no user object yet.
|
|
57
|
+
*/
|
|
58
|
+
export async function lifecycleRefusalFor(
|
|
59
|
+
db: AuthDatabase,
|
|
60
|
+
userId: string,
|
|
61
|
+
columns: Partial<LifecycleColumns> | null | undefined,
|
|
62
|
+
now: Date,
|
|
63
|
+
): Promise<PithyError | null> {
|
|
64
|
+
const held = columns ?? (await readLifecycleColumns(db, userId)) ?? {};
|
|
65
|
+
const standing = accountStanding(held, now);
|
|
66
|
+
if (standing.state === "active") return null;
|
|
67
|
+
const reason = standing.state === "suspended" ? await suspensionReason(db, userId) : null;
|
|
68
|
+
return lifecycleRefusal(userId, standing, reason);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The holder of a refused credential: whose session it is. Known because the credential itself is genuine. */
|
|
72
|
+
export interface RefusedHolder {
|
|
73
|
+
/** The account the session belongs to. */
|
|
74
|
+
readonly userId: string;
|
|
75
|
+
/** The session the request presented. */
|
|
76
|
+
readonly sessionId: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The refusal the session middleware reached for this request, keyed by the request's context.
|
|
81
|
+
*
|
|
82
|
+
* A WeakMap rather than a request variable because `PithyVars` is core's, and this is a fact only this
|
|
83
|
+
* capability's own guards read — a refused account already has no `AuthContext`, which is the part every
|
|
84
|
+
* other capability's guard needs. Keyed by the context the way `../http/resolve.ts` caches the instance, so
|
|
85
|
+
* it dies with the request.
|
|
86
|
+
*
|
|
87
|
+
* **The holder rides with it (#622).** A suspended account may still delete itself — the app stores require
|
|
88
|
+
* that a person can always leave — and that one route has to know whose account the refused credential
|
|
89
|
+
* opens. Nothing else reads it: the holder is reachable only through `accountHolder`, and only that route uses it.
|
|
90
|
+
*/
|
|
91
|
+
const refusals = new WeakMap<object, { refusal: PithyError; holder: RefusedHolder | undefined }>();
|
|
92
|
+
|
|
93
|
+
/** Remember that this request's credential belongs to an account that may not act, and whose it is. */
|
|
94
|
+
export function noteRefusal(context: object, refusal: PithyError, holder?: RefusedHolder): void {
|
|
95
|
+
refusals.set(context, { refusal, holder });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The refusal the session middleware reached for this request, if it reached one. */
|
|
99
|
+
export function noticedRefusal(context: object): PithyError | undefined {
|
|
100
|
+
return refusals.get(context)?.refusal;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The holder of a **suspended** account's credential on this request, or `undefined` (#622).
|
|
105
|
+
*
|
|
106
|
+
* Only a suspension: a deleted account has nothing left to delete, and a check that could not be made has
|
|
107
|
+
* established nobody. The one reader is the self-service deletion, through `../http/middleware.ts`.
|
|
108
|
+
*/
|
|
109
|
+
export function suspendedHolder(context: object): RefusedHolder | undefined {
|
|
110
|
+
const noted = refusals.get(context);
|
|
111
|
+
return noted?.refusal.payload.code === "auth/account_suspended" ? noted.holder : undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The header a sign-in carries to ask for a session that can do nothing but delete its account, and the one
|
|
116
|
+
* value it takes (#622).
|
|
117
|
+
*
|
|
118
|
+
* A suspension revokes every session the account holds and refuses every new one, so without this a suspended
|
|
119
|
+
* person would hold no credential and could get none — and the one route a suspension leaves open, deleting the
|
|
120
|
+
* account, would be one nobody could reach. With it, the sign-in completes: the person still proves who they are,
|
|
121
|
+
* by the code, the link or the provider, exactly as for any sign-in. **The session that results is still a
|
|
122
|
+
* suspended account's**, so the session middleware refuses it everywhere, Better Auth's own endpoints included,
|
|
123
|
+
* and only `DELETE /auth/account` admits it. Nothing about the header is trusted beyond that: it asks for a
|
|
124
|
+
* session no more capable than none, save for leaving.
|
|
125
|
+
*/
|
|
126
|
+
export const ACCOUNT_DELETION_INTENT_HEADER = "x-pithy-intent";
|
|
127
|
+
/** The value of `ACCOUNT_DELETION_INTENT_HEADER` that asks for a deletion-only session. */
|
|
128
|
+
export const ACCOUNT_DELETION_INTENT = "delete-account";
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Whether a sign-in refused with `refusal` may still create its session: only a **suspended** account's, and only
|
|
132
|
+
* when the request asks for nothing but deleting it. A deleted account has nothing left to delete, and a check
|
|
133
|
+
* that could not be made has established nobody, so neither is admitted.
|
|
134
|
+
*/
|
|
135
|
+
export function admitsDeletionSignIn(refusal: PithyError, headers: Headers | null | undefined): boolean {
|
|
136
|
+
if (refusal.payload.code !== "auth/account_suspended") return false;
|
|
137
|
+
const asked = headers?.get(ACCOUNT_DELETION_INTENT_HEADER)?.trim().toLowerCase();
|
|
138
|
+
return asked === ACCOUNT_DELETION_INTENT;
|
|
139
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { D1Database } from "@cloudflare/workers-types";
|
|
5
|
+
import type { UserLifecycleActorType } from "../data/userLifecycle";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The four seams an adopter's own code follows the account lifecycle through, without polling (#620).
|
|
9
|
+
*
|
|
10
|
+
* **On the transition, not on a route.** An account is suspended from the management surface today and may be
|
|
11
|
+
* from somewhere else tomorrow; a listener hung off one route would miss the others, which is the argument
|
|
12
|
+
* `onSessionRevoked` already makes for the session row. `./transitions.ts` is the only place a transition is
|
|
13
|
+
* written, so it is the only place these fire — once per transition that actually happened, never for a
|
|
14
|
+
* request that found the account already in the state it asked for.
|
|
15
|
+
*
|
|
16
|
+
* **Non-fatal by contract.** By the time a hook runs the transition is written and recorded. A hook that throws
|
|
17
|
+
* is logged and swallowed, so it can neither undo the transition nor turn it into an error the caller retries
|
|
18
|
+
* — a retry would find the account already moved and fire nothing, and the adopter's side effect would be
|
|
19
|
+
* lost either way.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** What happened, handed to every hook. */
|
|
23
|
+
export interface UserLifecycleHookEvent {
|
|
24
|
+
/** The account it happened to. */
|
|
25
|
+
readonly userId: string;
|
|
26
|
+
/** Who made the transition: the kind, and the principal's id where there is one. */
|
|
27
|
+
readonly actor: { readonly type: UserLifecycleActorType; readonly id: string | null };
|
|
28
|
+
/** The reason given, or null when the transition needed none. */
|
|
29
|
+
readonly reason: string | null;
|
|
30
|
+
/** When the transition was written. */
|
|
31
|
+
readonly at: Date;
|
|
32
|
+
/** For a suspension, when it ends by itself; null for one that lasts until a reinstatement. */
|
|
33
|
+
readonly suspendedUntil?: Date | null;
|
|
34
|
+
/** For a deletion, when the account's data may be erased. */
|
|
35
|
+
readonly purgeAfter?: Date | null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* One hook. Handed the request's D1 binding, for the reason `SessionRevokedListener` is: the listener almost
|
|
40
|
+
* certainly writes to the same database under a different capability's view of it.
|
|
41
|
+
*/
|
|
42
|
+
export type UserLifecycleListener = (event: UserLifecycleHookEvent, d1: D1Database) => void | Promise<void>;
|
|
43
|
+
|
|
44
|
+
/** The four hooks, each optional. Passed to `auth()` beside the config. */
|
|
45
|
+
export interface UserLifecycleHooks {
|
|
46
|
+
/** An account was suspended. */
|
|
47
|
+
readonly onUserSuspended?: UserLifecycleListener;
|
|
48
|
+
/** A suspended account was reinstated. */
|
|
49
|
+
readonly onUserReinstated?: UserLifecycleListener;
|
|
50
|
+
/** An account was deleted — by an operator or by its owner — and its purge window began. */
|
|
51
|
+
readonly onUserDeleted?: UserLifecycleListener;
|
|
52
|
+
/** A deleted account's data was erased. The last thing that happens to it. */
|
|
53
|
+
readonly onUserPurged?: UserLifecycleListener;
|
|
54
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The longest reason the kit stores. It is shown to the person, so it is a sentence, not a case file.
|
|
6
|
+
*
|
|
7
|
+
* A leaf with no imports, because two programs read it: the transitions, which refuse a longer one, and the
|
|
8
|
+
* request schemas in `../http/schemas.ts`, which a browser program compiles (`tooling/browser-scopes`). Kept
|
|
9
|
+
* in `./transitions.ts`, it pulled the email capability and the Workers types into that program (#621).
|
|
10
|
+
*/
|
|
11
|
+
export const MAX_REASON = 500;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
|
|
5
|
+
import type { EmailEnqueueEnv } from "@pithy-sh/email/src/capability";
|
|
6
|
+
import type { Context } from "hono";
|
|
7
|
+
import type { AuthWiring } from "../capability";
|
|
8
|
+
import { authDatabase } from "../data/tables";
|
|
9
|
+
import { resolveDb } from "../http/resolve";
|
|
10
|
+
import type { LifecycleAuditContext, LifecycleDeps } from "./transitions";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The transitions' dependencies, resolved from one request — what a lifecycle route hands `./transitions.ts`.
|
|
14
|
+
*
|
|
15
|
+
* One function so every route resolves them the same way: this request's database, its audit seam and logger,
|
|
16
|
+
* the composed email capability's enqueue bound to this request's env, and the adopter's hooks as `auth()` was
|
|
17
|
+
* handed them. A route that assembled its own would be the second place a hook could be forgotten.
|
|
18
|
+
*
|
|
19
|
+
* `context` is what the caller adds to each audit event: the request's correlation, and for a management call
|
|
20
|
+
* the connection it came through. The caller passes it because only the caller knows who it is.
|
|
21
|
+
*/
|
|
22
|
+
export function lifecycleDeps(
|
|
23
|
+
c: Context<PithyHonoEnv>,
|
|
24
|
+
wiring: AuthWiring,
|
|
25
|
+
context?: LifecycleAuditContext,
|
|
26
|
+
): LifecycleDeps {
|
|
27
|
+
const d1 = resolveDb(c.env, wiring.config.database);
|
|
28
|
+
const enqueue = wiring.enqueueEmail;
|
|
29
|
+
return {
|
|
30
|
+
db: authDatabase(d1),
|
|
31
|
+
d1,
|
|
32
|
+
emit: c.var.emit,
|
|
33
|
+
config: wiring.config,
|
|
34
|
+
hooks: wiring.lifecycleHooks ?? {},
|
|
35
|
+
enqueueEmail: enqueue ? (input) => enqueue(c.env as unknown as EmailEnqueueEnv, input) : undefined,
|
|
36
|
+
log: c.var.log?.child("auth"),
|
|
37
|
+
...(context ? { context } : {}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { PithyError } from "@pithy-sh/core/src/error/pithyError";
|
|
5
|
+
import type { z } from "zod";
|
|
6
|
+
import { User } from "../data/betterAuth";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* What an account's four lifecycle columns mean, decided once.
|
|
10
|
+
*
|
|
11
|
+
* Every enforcement point — the session middleware, sign-in, token refresh — reads the state through
|
|
12
|
+
* {@link accountStanding} and refuses through {@link lifecycleRefusal}. Enforcement written twice is
|
|
13
|
+
* enforcement that disagrees, and the first disagreement would be a suspension one door honors and another
|
|
14
|
+
* does not.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The four columns, decoded off whatever carries them: a `pithy_auth_users` row, or the user object Better
|
|
19
|
+
* Auth resolved for a session, which carries them because `../data/kitFields.ts` declares them. Unknown keys
|
|
20
|
+
* are dropped, and a key that is absent — a row read before `0004_user_lifecycle` — reads as null.
|
|
21
|
+
*/
|
|
22
|
+
export const LifecycleColumns = User.pick({
|
|
23
|
+
suspendedAt: true,
|
|
24
|
+
suspendedUntil: true,
|
|
25
|
+
deletedAt: true,
|
|
26
|
+
purgeAfter: true,
|
|
27
|
+
}).describe("An account's lifecycle columns, as `pithy_auth_users` stores them.");
|
|
28
|
+
export type LifecycleColumns = z.output<typeof LifecycleColumns>;
|
|
29
|
+
|
|
30
|
+
/** Where an account stands, at one instant. */
|
|
31
|
+
export type AccountStanding =
|
|
32
|
+
| { readonly state: "active" }
|
|
33
|
+
| { readonly state: "suspended"; readonly until: Date | null }
|
|
34
|
+
| { readonly state: "deleted"; readonly purgeAfter: Date | null };
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Where an account stands at `now`.
|
|
38
|
+
*
|
|
39
|
+
* **Deleted outranks suspended.** An account deleted while it was suspended is deleted: the suspension's end
|
|
40
|
+
* passing must not reopen it.
|
|
41
|
+
*
|
|
42
|
+
* **A suspension past its `suspendedUntil` is not a suspension**, and no write expires it. The end is
|
|
43
|
+
* exclusive — at the instant it names, the account is active again. A column nobody has cleared is a
|
|
44
|
+
* fact about the past, not about now, and reading it that way is what lets a timed suspension end on time
|
|
45
|
+
* with nothing scheduled to end it.
|
|
46
|
+
*
|
|
47
|
+
* **A deletion past its `purgeAfter` is still a deletion.** Only the purge ends that state, by erasing the
|
|
48
|
+
* account, and until it has run the account must stay shut.
|
|
49
|
+
*/
|
|
50
|
+
export function accountStanding(columns: Partial<LifecycleColumns>, now: Date): AccountStanding {
|
|
51
|
+
if (columns.deletedAt) return { state: "deleted", purgeAfter: columns.purgeAfter ?? null };
|
|
52
|
+
if (columns.suspendedAt) {
|
|
53
|
+
const until = columns.suspendedUntil ?? null;
|
|
54
|
+
if (until === null || until.getTime() > now.getTime()) return { state: "suspended", until };
|
|
55
|
+
}
|
|
56
|
+
return { state: "active" };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** What a suspended account is told when nobody wrote a reason. */
|
|
60
|
+
const UNEXPLAINED_SUSPENSION = "This account is suspended.";
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The refusal for an account that may not act, or `null` for one that may.
|
|
64
|
+
*
|
|
65
|
+
* **The reason an operator gave is the public `message`**, because it is written for the person who is locked
|
|
66
|
+
* out and it is the one thing their screen cannot invent. `params` carries the end of a suspension, or the
|
|
67
|
+
* last day a deletion can be undone, as ISO-8601, for a client that renders the date in its reader's own
|
|
68
|
+
* words. Neither the account id nor who acted crosses: `detail` holds the id for the log, and `clientError`
|
|
69
|
+
* strips it with `action`.
|
|
70
|
+
*
|
|
71
|
+
* 403 for both, never 401: the credential is genuine, and signing in again cannot help.
|
|
72
|
+
*/
|
|
73
|
+
export function lifecycleRefusal(userId: string, standing: AccountStanding, reason: string | null): PithyError | null {
|
|
74
|
+
if (standing.state === "active") return null;
|
|
75
|
+
if (standing.state === "suspended") {
|
|
76
|
+
return new PithyError({
|
|
77
|
+
code: "auth/account_suspended",
|
|
78
|
+
status: 403,
|
|
79
|
+
message: reason ?? UNEXPLAINED_SUSPENSION,
|
|
80
|
+
...(standing.until ? { params: { suspendedUntil: standing.until.toISOString() } } : {}),
|
|
81
|
+
action: "An operator suspended this account. Reinstate it from the management surface, or let it run out.",
|
|
82
|
+
detail: `user ${userId} is suspended${standing.until ? ` until ${standing.until.toISOString()}` : ""}`,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return new PithyError({
|
|
86
|
+
code: "auth/account_deleted",
|
|
87
|
+
status: 403,
|
|
88
|
+
message: "This account is deleted.",
|
|
89
|
+
...(standing.purgeAfter ? { params: { purgeAfter: standing.purgeAfter.toISOString() } } : {}),
|
|
90
|
+
action: "The account is inside its purge window. Restore it from the management surface before the purge runs.",
|
|
91
|
+
detail: `user ${userId} is deleted${standing.purgeAfter ? `, purge after ${standing.purgeAfter.toISOString()}` : ""}`,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Whether a caught error is one of the two lifecycle refusals. */
|
|
96
|
+
export function isLifecycleRefusal(error: unknown): error is PithyError {
|
|
97
|
+
return (
|
|
98
|
+
error instanceof PithyError &&
|
|
99
|
+
(error.payload.code === "auth/account_suspended" || error.payload.code === "auth/account_deleted")
|
|
100
|
+
);
|
|
101
|
+
}
|