@pithy-sh/auth 0.10.0 → 0.12.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 +30 -2
- package/dist/admin/users.js +1 -1
- package/dist/audit/actions.d.ts +58 -0
- package/dist/audit/actions.d.ts.map +1 -1
- package/dist/audit/actions.js +59 -1
- package/dist/audit/emit.d.ts +36 -0
- package/dist/audit/emit.d.ts.map +1 -1
- package/dist/audit/emit.js +48 -2
- package/dist/audit/evidence.d.ts +8 -2
- package/dist/audit/evidence.d.ts.map +1 -1
- package/dist/capability.d.ts +47 -8
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +56 -6
- package/dist/client/api.d.ts +55 -12
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +57 -18
- package/dist/client/bearer.d.ts +110 -0
- package/dist/client/bearer.d.ts.map +1 -0
- package/dist/client/bearer.js +265 -0
- package/dist/client/handoff.d.ts +77 -0
- package/dist/client/handoff.d.ts.map +1 -0
- package/dist/client/handoff.js +119 -0
- package/dist/client/mcp.d.ts +70 -0
- package/dist/client/mcp.d.ts.map +1 -0
- package/dist/client/mcp.js +65 -0
- package/dist/data/betterAuth.d.ts +3 -2
- package/dist/data/betterAuth.d.ts.map +1 -1
- package/dist/data/betterAuth.js +5 -3
- package/dist/data/kitFields.d.ts +5 -0
- package/dist/data/kitFields.d.ts.map +1 -1
- package/dist/data/kitFields.js +5 -0
- package/dist/data/tables.d.ts +26 -4
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/tables.js +5 -3
- package/dist/data/userLifecycle.d.ts +10 -0
- package/dist/data/userLifecycle.d.ts.map +1 -1
- package/dist/data/userLifecycle.js +8 -3
- package/dist/data/verificationOutcome.d.ts +53 -0
- package/dist/data/verificationOutcome.d.ts.map +1 -0
- package/dist/data/verificationOutcome.js +50 -0
- package/dist/email/send.js +6 -2
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +319 -8
- package/dist/http/csrf.d.ts.map +1 -1
- package/dist/http/csrf.js +2 -1
- package/dist/http/guards.d.ts +15 -10
- package/dist/http/guards.d.ts.map +1 -1
- package/dist/http/guards.js +76 -10
- package/dist/http/handoff.d.ts +76 -0
- package/dist/http/handoff.d.ts.map +1 -0
- package/dist/http/handoff.js +316 -0
- package/dist/http/middleware.d.ts +37 -1
- package/dist/http/middleware.d.ts.map +1 -1
- package/dist/http/middleware.js +68 -6
- package/dist/http/resolve.d.ts.map +1 -1
- package/dist/http/resolve.js +9 -3
- package/dist/http/responses.d.ts +322 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +202 -5
- package/dist/http/routes.d.ts +3 -0
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +78 -5
- package/dist/http/schemas.d.ts +114 -0
- package/dist/http/schemas.d.ts.map +1 -1
- package/dist/http/schemas.js +94 -1
- package/dist/http/views.d.ts +60 -3
- package/dist/http/views.d.ts.map +1 -1
- package/dist/http/views.js +143 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/instance/auth.d.ts +148 -10
- package/dist/instance/auth.d.ts.map +1 -1
- package/dist/instance/auth.js +87 -42
- package/dist/instance/plugins.d.ts +6 -0
- package/dist/instance/plugins.d.ts.map +1 -1
- package/dist/instance/plugins.js +14 -1
- package/dist/ledger/read.d.ts +53 -0
- package/dist/ledger/read.d.ts.map +1 -0
- package/dist/ledger/read.js +85 -0
- package/dist/ledger/record.d.ts +35 -0
- package/dist/ledger/record.d.ts.map +1 -0
- package/dist/ledger/record.js +98 -0
- 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/erasure.d.ts +9 -0
- package/dist/lifecycle/erasure.d.ts.map +1 -0
- package/dist/lifecycle/erasure.js +96 -0
- package/dist/lifecycle/inactivity.d.ts +19 -0
- package/dist/lifecycle/inactivity.d.ts.map +1 -0
- package/dist/lifecycle/inactivity.js +28 -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 +5 -2
- package/dist/lifecycle/request.d.ts.map +1 -1
- package/dist/lifecycle/request.js +6 -2
- package/dist/lifecycle/transitions.d.ts +179 -18
- package/dist/lifecycle/transitions.d.ts.map +1 -1
- package/dist/lifecycle/transitions.js +391 -70
- package/dist/mcp/argumentClass.d.ts +51 -0
- package/dist/mcp/argumentClass.d.ts.map +1 -0
- package/dist/mcp/argumentClass.js +69 -0
- package/dist/mcp/capability.d.ts +50 -0
- package/dist/mcp/capability.d.ts.map +1 -0
- package/dist/mcp/capability.js +140 -0
- package/dist/mcp/clientMetadata.d.ts +40 -0
- package/dist/mcp/clientMetadata.d.ts.map +1 -0
- package/dist/mcp/clientMetadata.js +68 -0
- package/dist/mcp/consent.d.ts +49 -0
- package/dist/mcp/consent.d.ts.map +1 -0
- package/dist/mcp/consent.js +69 -0
- package/dist/mcp/dispatch.d.ts +35 -0
- package/dist/mcp/dispatch.d.ts.map +1 -0
- package/dist/mcp/dispatch.js +135 -0
- package/dist/mcp/floor.d.ts +37 -0
- package/dist/mcp/floor.d.ts.map +1 -0
- package/dist/mcp/floor.js +41 -0
- package/dist/mcp/host.d.ts +34 -0
- package/dist/mcp/host.d.ts.map +1 -0
- package/dist/mcp/host.js +2 -0
- package/dist/mcp/http/redirectList.d.ts +9 -0
- package/dist/mcp/http/redirectList.d.ts.map +1 -0
- package/dist/mcp/http/redirectList.js +24 -0
- package/dist/mcp/http/responses.d.ts +143 -0
- package/dist/mcp/http/responses.d.ts.map +1 -0
- package/dist/mcp/http/responses.js +83 -0
- package/dist/mcp/http/routes.d.ts +28 -0
- package/dist/mcp/http/routes.d.ts.map +1 -0
- package/dist/mcp/http/routes.js +517 -0
- package/dist/mcp/http/schemas.d.ts +24 -0
- package/dist/mcp/http/schemas.d.ts.map +1 -0
- package/dist/mcp/http/schemas.js +18 -0
- package/dist/mcp/marker.d.ts +15 -0
- package/dist/mcp/marker.d.ts.map +1 -0
- package/dist/mcp/marker.js +15 -0
- package/dist/mcp/provider.d.ts +78 -0
- package/dist/mcp/provider.d.ts.map +1 -0
- package/dist/mcp/provider.js +108 -0
- package/dist/mcp/purge.d.ts +15 -0
- package/dist/mcp/purge.d.ts.map +1 -0
- package/dist/mcp/purge.js +31 -0
- package/dist/mcp/rpc.d.ts +79 -0
- package/dist/mcp/rpc.d.ts.map +1 -0
- package/dist/mcp/rpc.js +103 -0
- package/dist/mcp/toolAudit.d.ts +76 -0
- package/dist/mcp/toolAudit.d.ts.map +1 -0
- package/dist/mcp/toolAudit.js +86 -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/0006_verification_outcomes.d.ts +15 -0
- package/dist/migrations/0006_verification_outcomes.d.ts.map +1 -0
- package/dist/migrations/0006_verification_outcomes.js +35 -0
- package/dist/migrations/0007_erasure_record.d.ts +17 -0
- package/dist/migrations/0007_erasure_record.d.ts.map +1 -0
- package/dist/migrations/0007_erasure_record.js +36 -0
- package/dist/migrations/0008_last_active.d.ts +15 -0
- package/dist/migrations/0008_last_active.d.ts.map +1 -0
- package/dist/migrations/0008_last_active.js +29 -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 +5 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +10 -2
- package/dist/peer.d.ts +3 -2
- package/dist/peer.d.ts.map +1 -1
- package/dist/processing/activities.d.ts +6 -0
- package/dist/processing/activities.d.ts.map +1 -0
- package/dist/processing/activities.js +12 -0
- package/dist/purge/contribution.d.ts +62 -0
- package/dist/purge/contribution.d.ts.map +1 -0
- package/dist/purge/contribution.js +155 -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 +158 -0
- package/dist/purge/run.d.ts.map +1 -0
- package/dist/purge/run.js +205 -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 +71 -0
- package/dist/purge/workflow.d.ts.map +1 -0
- package/dist/purge/workflow.js +140 -0
- package/dist/test-utils/accountFootprint.d.ts +13 -0
- package/dist/test-utils/accountFootprint.d.ts.map +1 -0
- package/dist/test-utils/accountFootprint.js +49 -0
- package/dist/test-utils/liveApp.d.ts +6 -0
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +7 -2
- package/dist/token/handoff.d.ts +80 -0
- package/dist/token/handoff.d.ts.map +1 -0
- package/dist/token/handoff.js +136 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/account-lifecycle.md +176 -12
- package/docs/apple-signin.md +32 -4
- package/docs/facebook-oauth.md +2 -2
- package/docs/github-oauth.md +2 -2
- package/docs/google-oauth.md +9 -7
- package/docs/microsoft-oauth.md +2 -2
- package/package.json +11 -5
- package/pithy.manifest.json +2 -2
- package/pithy.mcp.manifest.json +36 -0
- package/src/audit/actions.ts +58 -0
- package/src/audit/emit.ts +66 -1
- package/src/audit/evidence.ts +8 -4
- package/src/capability.ts +122 -18
- package/src/client/api.ts +69 -19
- package/src/client/bearer.ts +388 -0
- package/src/client/handoff.ts +172 -0
- package/src/client/mcp.ts +140 -0
- package/src/data/betterAuth.ts +8 -4
- package/src/data/kitFields.ts +2 -0
- package/src/data/tables.ts +4 -2
- package/src/data/userLifecycle.ts +19 -4
- package/src/data/verificationOutcome.ts +86 -0
- package/src/email/send.ts +2 -2
- package/src/http/adminRoutes.ts +465 -4
- package/src/http/csrf.ts +4 -1
- package/src/http/guards.ts +79 -10
- package/src/http/handoff.ts +350 -0
- package/src/http/middleware.ts +74 -5
- package/src/http/resolve.ts +25 -25
- package/src/http/responses.ts +374 -3
- package/src/http/routes.ts +116 -5
- package/src/http/schemas.ts +195 -0
- package/src/http/views.ts +192 -3
- package/src/index.ts +2 -0
- package/src/instance/auth.ts +58 -3
- package/src/instance/plugins.ts +20 -2
- package/src/ledger/read.ts +133 -0
- package/src/ledger/record.ts +198 -0
- package/src/lifecycle/audited.ts +104 -0
- package/src/lifecycle/enforce.ts +55 -5
- package/src/lifecycle/erasure.ts +118 -0
- package/src/lifecycle/inactivity.ts +56 -0
- package/src/lifecycle/reason.ts +11 -0
- package/src/lifecycle/request.ts +10 -2
- package/src/lifecycle/transitions.ts +552 -93
- package/src/mcp/argumentClass.ts +112 -0
- package/src/mcp/capability.ts +194 -0
- package/src/mcp/clientMetadata.ts +81 -0
- package/src/mcp/consent.ts +95 -0
- package/src/mcp/dispatch.ts +154 -0
- package/src/mcp/floor.ts +62 -0
- package/src/mcp/host.ts +36 -0
- package/src/mcp/http/redirectList.ts +26 -0
- package/src/mcp/http/responses.ts +157 -0
- package/src/mcp/http/routes.ts +635 -0
- package/src/mcp/http/schemas.ts +37 -0
- package/src/mcp/marker.ts +18 -0
- package/src/mcp/provider.ts +151 -0
- package/src/mcp/purge.ts +39 -0
- package/src/mcp/rpc.ts +135 -0
- package/src/mcp/toolAudit.ts +132 -0
- package/src/migrations/0005_purge_once.ts +42 -0
- package/src/migrations/0006_verification_outcomes.ts +51 -0
- package/src/migrations/0007_erasure_record.ts +43 -0
- package/src/migrations/0008_last_active.ts +30 -0
- package/src/migrations/pluginTables.ts +19 -1
- package/src/migrations/set.ts +9 -1
- package/src/processing/activities.ts +14 -0
- package/src/purge/contribution.ts +218 -0
- package/src/purge/retryPolicy.ts +26 -0
- package/src/purge/run.ts +348 -0
- package/src/purge/specs.ts +95 -0
- package/src/purge/start.ts +79 -0
- package/src/purge/workflow.ts +202 -0
- package/src/seeds/example.ts +2 -2
- package/src/test-utils/accountFootprint.ts +104 -0
- package/src/test-utils/liveApp.ts +10 -1
- package/src/token/handoff.ts +180 -0
- package/src/version.generated.ts +1 -1
package/dist/http/views.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { verificationStateAt } from "../data/verificationOutcome.js";
|
|
4
|
+
import { accountStanding } from "../lifecycle/state.js";
|
|
3
5
|
//#region src/http/views.ts
|
|
4
6
|
/**
|
|
5
7
|
* The admin projections — what a management client is shown of a user, a session, and a device.
|
|
@@ -25,8 +27,12 @@
|
|
|
25
27
|
* `locale` is projected for the same reason: a support pane answering "why is this person getting
|
|
26
28
|
* English emails" needs to see whether they ever chose, and null — never chosen — is the answer half
|
|
27
29
|
* the time. It is a preference, not a credential.
|
|
30
|
+
*
|
|
31
|
+
* Where the account stands is projected too (#813), judged at `now`: the listing does not filter a suspended or
|
|
32
|
+
* deleted account out, so without it a pane sees the person and cannot tell whether to offer suspend or reinstate.
|
|
33
|
+
* Not the reason and not who acted — those are the trail's.
|
|
28
34
|
*/
|
|
29
|
-
function userView(user) {
|
|
35
|
+
function userView(user, now) {
|
|
30
36
|
return {
|
|
31
37
|
id: user.id,
|
|
32
38
|
email: user.email,
|
|
@@ -35,7 +41,20 @@ function userView(user) {
|
|
|
35
41
|
image: user.image,
|
|
36
42
|
locale: user.locale,
|
|
37
43
|
createdAt: user.createdAt.toISOString(),
|
|
38
|
-
updatedAt: user.updatedAt.toISOString()
|
|
44
|
+
updatedAt: user.updatedAt.toISOString(),
|
|
45
|
+
...standingView(accountStanding(user, now))
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Where an account stands, as the wire carries it (#813) — the organization view's shape: the state, the end of a
|
|
50
|
+
* suspension in force, and the last day a deletion can be undone. Read through `accountStanding`, the function
|
|
51
|
+
* every enforcement point reads, so a suspension past its end reads `active` here exactly as it does at the door.
|
|
52
|
+
*/
|
|
53
|
+
function standingView(standing) {
|
|
54
|
+
return {
|
|
55
|
+
state: standing.state,
|
|
56
|
+
suspendedUntil: standing.state === "suspended" ? iso(standing.until) : null,
|
|
57
|
+
purgeAfter: standing.state === "deleted" ? iso(standing.purgeAfter) : null
|
|
39
58
|
};
|
|
40
59
|
}
|
|
41
60
|
/**
|
|
@@ -84,5 +103,126 @@ function deviceView(device) {
|
|
|
84
103
|
createdAt: device.createdAt.toISOString()
|
|
85
104
|
};
|
|
86
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* One verification ledger row, as a management client sees it (#829). `state` is judged at `now`, the moment the
|
|
108
|
+
* read took, so it agrees with the counts beside it.
|
|
109
|
+
*/
|
|
110
|
+
function verificationView(row, now) {
|
|
111
|
+
return {
|
|
112
|
+
verificationId: row.verificationId,
|
|
113
|
+
type: row.type,
|
|
114
|
+
state: verificationStateAt(row, now),
|
|
115
|
+
userId: row.userId,
|
|
116
|
+
emailJobId: row.emailJobId,
|
|
117
|
+
issuedAt: row.issuedAt.toISOString(),
|
|
118
|
+
expiresAt: row.expiresAt.toISOString(),
|
|
119
|
+
usedAt: row.usedAt?.toISOString() ?? null
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The suspension projection (#621): the suspension the transition left in force, and the sessions the route
|
|
124
|
+
* revoked after it. Dates cross as ISO-8601, like every other response here.
|
|
125
|
+
*/
|
|
126
|
+
function suspensionView(userId, result, sessionsRevoked) {
|
|
127
|
+
return {
|
|
128
|
+
userId,
|
|
129
|
+
state: "suspended",
|
|
130
|
+
outcome: result.updated ? "updated" : "suspended",
|
|
131
|
+
suspendedAt: result.suspendedAt.toISOString(),
|
|
132
|
+
suspendedUntil: result.suspendedUntil?.toISOString() ?? null,
|
|
133
|
+
sessionsRevoked,
|
|
134
|
+
mailed: result.mailed
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** The reinstatement projection (#621). A call that found no suspension in force is `unchanged`. */
|
|
138
|
+
function reinstatementView(userId, result) {
|
|
139
|
+
return {
|
|
140
|
+
userId,
|
|
141
|
+
state: "active",
|
|
142
|
+
outcome: result.changed ? "reinstated" : "unchanged",
|
|
143
|
+
mailed: result.mailed
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The deletion projection (#622): the deletion the transition left in force, the sessions the route revoked
|
|
148
|
+
* after it, and what became of the purge.
|
|
149
|
+
*/
|
|
150
|
+
function deletionView(userId, mode, result, purge, sessionsRevoked) {
|
|
151
|
+
return {
|
|
152
|
+
userId,
|
|
153
|
+
state: "deleted",
|
|
154
|
+
mode,
|
|
155
|
+
outcome: result.outcome,
|
|
156
|
+
deletedAt: result.deletedAt.toISOString(),
|
|
157
|
+
purgeAfter: result.purgeAfter.toISOString(),
|
|
158
|
+
purge,
|
|
159
|
+
sessionsRevoked,
|
|
160
|
+
mailed: result.mailed
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/** The restoration projection (#622). A call that found the account not deleted is `unchanged`. */
|
|
164
|
+
function restorationView(userId, result) {
|
|
165
|
+
return {
|
|
166
|
+
userId,
|
|
167
|
+
state: result.state,
|
|
168
|
+
outcome: result.changed ? "restored" : "unchanged"
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** The self-service deletion projection (#622). */
|
|
172
|
+
function accountDeletionView(result) {
|
|
173
|
+
return {
|
|
174
|
+
state: "deleted",
|
|
175
|
+
purgeAfter: result.purgeAfter.toISOString(),
|
|
176
|
+
mailed: result.mailed
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/** A date as the wire carries it, or null. */
|
|
180
|
+
function iso(date) {
|
|
181
|
+
return date ? date.toISOString() : null;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* What auth holds about one account, as its export carries it (#622) — the person's own data, projected through
|
|
185
|
+
* the same views a support pane sees, so a session token, a provider token and a push token are absent here by
|
|
186
|
+
* the same construction that keeps them out of every other response. The operator who made a transition is
|
|
187
|
+
* theirs to disclose, not the person's, so the history carries the kind of actor and not its id.
|
|
188
|
+
*/
|
|
189
|
+
function authUserExportView(input) {
|
|
190
|
+
const { user } = input;
|
|
191
|
+
return {
|
|
192
|
+
user: {
|
|
193
|
+
...userView(user, input.now),
|
|
194
|
+
suspendedAt: iso(user.suspendedAt),
|
|
195
|
+
suspendedUntil: iso(user.suspendedUntil),
|
|
196
|
+
deletedAt: iso(user.deletedAt),
|
|
197
|
+
purgeAfter: iso(user.purgeAfter)
|
|
198
|
+
},
|
|
199
|
+
sessions: input.sessions.map(sessionView),
|
|
200
|
+
providers: input.accounts.map((account) => ({
|
|
201
|
+
providerId: account.providerId,
|
|
202
|
+
createdAt: account.createdAt.toISOString()
|
|
203
|
+
})),
|
|
204
|
+
devices: input.devices.map(deviceView),
|
|
205
|
+
history: input.history.map((event) => ({
|
|
206
|
+
action: event.action,
|
|
207
|
+
actorType: event.actorType,
|
|
208
|
+
reason: event.reason,
|
|
209
|
+
suspendedUntil: iso(event.suspendedUntil),
|
|
210
|
+
createdAt: event.createdAt.toISOString()
|
|
211
|
+
})),
|
|
212
|
+
verifications: (input.verifications ?? []).map((row) => verificationView(row, input.now)),
|
|
213
|
+
plugins: input.plugins ?? {}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/** The export document (#622): who it is about, when it was read, and every capability's part. */
|
|
217
|
+
function exportView(userId, exportedAt, entries) {
|
|
218
|
+
return {
|
|
219
|
+
subject: {
|
|
220
|
+
type: "user",
|
|
221
|
+
id: userId
|
|
222
|
+
},
|
|
223
|
+
exportedAt: exportedAt.toISOString(),
|
|
224
|
+
capabilities: entries.map((entry) => ({ ...entry }))
|
|
225
|
+
};
|
|
226
|
+
}
|
|
87
227
|
//#endregion
|
|
88
|
-
export { deviceView, sessionView, userView };
|
|
228
|
+
export { accountDeletionView, authUserExportView, deletionView, deviceView, exportView, reinstatementView, restorationView, sessionView, standingView, suspensionView, userView, verificationView };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,4 +13,6 @@ export { type AuthDatabase, authDatabase } from "./data/tables";
|
|
|
13
13
|
export { DEVICE_HEADERS, type DeviceMeta } from "./device/registry";
|
|
14
14
|
export { requireAuth } from "./http/middleware";
|
|
15
15
|
export { AppleOAuthCredentials, AUTH_APPLE_CREDENTIALS, AUTH_GOOGLE_CREDENTIALS, AUTH_SESSION_SECRET, authSecretsRegistry, GoogleOAuthCredentials, } from "./instance/secrets";
|
|
16
|
+
export { type McpCapability, McpConfig, type McpConfigInput, mcp } from "./mcp/capability";
|
|
17
|
+
export { McpFloor } from "./mcp/floor";
|
|
16
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,KAAK,cAAc,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC7G,OAAO,EAAE,KAAK,MAAM,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,KAAK,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,KAAK,cAAc,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC7G,OAAO,EAAE,KAAK,MAAM,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,KAAK,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,aAAa,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { AuthAuditActions } from "./audit/actions.js";
|
|
3
4
|
import { DevicePlatform } from "./data/device.js";
|
|
4
5
|
import { authDatabase } from "./data/tables.js";
|
|
5
6
|
import { AUTH_APPLE_CREDENTIALS, AUTH_GOOGLE_CREDENTIALS, AUTH_SESSION_SECRET, AppleOAuthCredentials, GoogleOAuthCredentials, authSecretsRegistry } from "./instance/secrets.js";
|
|
6
|
-
import { AuthAuditActions } from "./audit/actions.js";
|
|
7
7
|
import { DEVICE_HEADERS } from "./device/registry.js";
|
|
8
8
|
import { requireAuth } from "./http/middleware.js";
|
|
9
9
|
import { AuthConfig, auth, isAuthCapability } from "./capability.js";
|
|
10
|
-
|
|
10
|
+
import { McpFloor } from "./mcp/floor.js";
|
|
11
|
+
import { McpConfig, mcp } from "./mcp/capability.js";
|
|
12
|
+
export { AUTH_APPLE_CREDENTIALS, AUTH_GOOGLE_CREDENTIALS, AUTH_SESSION_SECRET, AppleOAuthCredentials, AuthAuditActions, AuthConfig, DEVICE_HEADERS, DevicePlatform, GoogleOAuthCredentials, McpConfig, McpFloor, auth, authDatabase, authSecretsRegistry, isAuthCapability, mcp, requireAuth };
|
package/dist/instance/auth.d.ts
CHANGED
|
@@ -218,6 +218,37 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
218
218
|
throw: true;
|
|
219
219
|
};
|
|
220
220
|
databaseHooks: {
|
|
221
|
+
/**
|
|
222
|
+
* The verification ledger's two hooks on Better Auth's own verification rows (#829).
|
|
223
|
+
*
|
|
224
|
+
* **`create.after` remembers the row** — a sign-in link or code about to be sent, OAuth state, or a wrong
|
|
225
|
+
* code re-created with one more attempt counted; `../ledger/record.ts` tells them apart by what follows.
|
|
226
|
+
* **`delete.before` remembers the row about to be consumed**, and changes nothing: it returns nothing, so it
|
|
227
|
+
* never vetoes, and it is not a `delete.after` because claiming a verification removal the way
|
|
228
|
+
* `claimedDelete` does would delete the row before the consume could read it.
|
|
229
|
+
*/
|
|
230
|
+
verification: {
|
|
231
|
+
create: {
|
|
232
|
+
after: (verification: {
|
|
233
|
+
id: string;
|
|
234
|
+
createdAt: Date;
|
|
235
|
+
updatedAt: Date;
|
|
236
|
+
value: string;
|
|
237
|
+
expiresAt: Date;
|
|
238
|
+
identifier: string;
|
|
239
|
+
} & Record<string, unknown>, ctx: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
240
|
+
};
|
|
241
|
+
delete: {
|
|
242
|
+
before: (verification: {
|
|
243
|
+
id: string;
|
|
244
|
+
createdAt: Date;
|
|
245
|
+
updatedAt: Date;
|
|
246
|
+
value: string;
|
|
247
|
+
expiresAt: Date;
|
|
248
|
+
identifier: string;
|
|
249
|
+
} & Record<string, unknown>, ctx: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
250
|
+
};
|
|
251
|
+
};
|
|
221
252
|
user: {
|
|
222
253
|
create: {
|
|
223
254
|
before: (user: {
|
|
@@ -359,6 +390,39 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
359
390
|
authenticatedAt: Date | null;
|
|
360
391
|
};
|
|
361
392
|
}>;
|
|
393
|
+
/**
|
|
394
|
+
* Stamp the sign-in link or code this session was made from as used (#829), and name the account a
|
|
395
|
+
* sign-up just created. Only a row consumed earlier in this same request is stamped, so a token
|
|
396
|
+
* refresh, an OAuth callback and every other session stamp nothing — see `../ledger/record.ts`.
|
|
397
|
+
* After, because the session exists by now: a sign-in the `before` above refused stamps nothing.
|
|
398
|
+
*/
|
|
399
|
+
after: (session: {
|
|
400
|
+
id: string;
|
|
401
|
+
createdAt: Date;
|
|
402
|
+
updatedAt: Date;
|
|
403
|
+
userId: string;
|
|
404
|
+
expiresAt: Date;
|
|
405
|
+
token: string;
|
|
406
|
+
ipAddress?: string | null | undefined;
|
|
407
|
+
userAgent?: string | null | undefined;
|
|
408
|
+
} & Record<string, unknown>, ctx: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
409
|
+
};
|
|
410
|
+
update: {
|
|
411
|
+
/**
|
|
412
|
+
* The activity clock again, for a session that stays open. Better Auth slides a session forward in place
|
|
413
|
+
* once `updateAge` has passed, and that refresh is an update, never a create, so the hook above never
|
|
414
|
+
* sees it. Without this, signing out after weeks of use on one session would read as weeks idle.
|
|
415
|
+
*/
|
|
416
|
+
after: (session: {
|
|
417
|
+
id: string;
|
|
418
|
+
createdAt: Date;
|
|
419
|
+
updatedAt: Date;
|
|
420
|
+
userId: string;
|
|
421
|
+
expiresAt: Date;
|
|
422
|
+
token: string;
|
|
423
|
+
ipAddress?: string | null | undefined;
|
|
424
|
+
userAgent?: string | null | undefined;
|
|
425
|
+
} & Record<string, unknown>) => Promise<void>;
|
|
362
426
|
};
|
|
363
427
|
/**
|
|
364
428
|
* Tell whoever keyed state on this session that it has gone, and record that it did.
|
|
@@ -452,6 +516,11 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
452
516
|
readonly required: false;
|
|
453
517
|
readonly input: false;
|
|
454
518
|
};
|
|
519
|
+
readonly lastActiveAt: {
|
|
520
|
+
readonly type: "number";
|
|
521
|
+
readonly required: false;
|
|
522
|
+
readonly input: false;
|
|
523
|
+
};
|
|
455
524
|
readonly locale: {
|
|
456
525
|
readonly type: "string";
|
|
457
526
|
readonly required: false;
|
|
@@ -558,11 +627,11 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
558
627
|
handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
|
|
559
628
|
}[];
|
|
560
629
|
};
|
|
561
|
-
options: import("better-auth/plugins
|
|
630
|
+
options: import("better-auth/plugins").BearerOptions | undefined;
|
|
562
631
|
}, {
|
|
563
632
|
id: "jwt";
|
|
564
633
|
version: string;
|
|
565
|
-
options: NoInfer<import("better-auth/plugins
|
|
634
|
+
options: NoInfer<import("better-auth/plugins").JwtOptions>;
|
|
566
635
|
init(ctx: import("better-auth").AuthContext): {
|
|
567
636
|
context: {
|
|
568
637
|
sessionConfig: {
|
|
@@ -713,7 +782,7 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
713
782
|
$Infer: {
|
|
714
783
|
body: {
|
|
715
784
|
payload: import("better-auth").JWTPayload;
|
|
716
|
-
overrideOptions?: import("better-auth/plugins
|
|
785
|
+
overrideOptions?: import("better-auth/plugins").JwtOptions | undefined;
|
|
717
786
|
};
|
|
718
787
|
};
|
|
719
788
|
};
|
|
@@ -891,7 +960,7 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
891
960
|
window: number;
|
|
892
961
|
max: number;
|
|
893
962
|
}[];
|
|
894
|
-
options: import("better-auth/plugins
|
|
963
|
+
options: import("better-auth/plugins").MagicLinkOptions;
|
|
895
964
|
}, {
|
|
896
965
|
id: "email-otp";
|
|
897
966
|
version: string;
|
|
@@ -1418,7 +1487,7 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
1418
1487
|
window: number;
|
|
1419
1488
|
max: number;
|
|
1420
1489
|
})[];
|
|
1421
|
-
options: import("better-auth/plugins
|
|
1490
|
+
options: import("better-auth/plugins").EmailOTPOptions;
|
|
1422
1491
|
$ERROR_CODES: {
|
|
1423
1492
|
OTP_EXPIRED: import("better-auth").RawError<"OTP_EXPIRED">;
|
|
1424
1493
|
INVALID_OTP: import("better-auth").RawError<"INVALID_OTP">;
|
|
@@ -1449,6 +1518,37 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
1449
1518
|
throw: true;
|
|
1450
1519
|
};
|
|
1451
1520
|
databaseHooks: {
|
|
1521
|
+
/**
|
|
1522
|
+
* The verification ledger's two hooks on Better Auth's own verification rows (#829).
|
|
1523
|
+
*
|
|
1524
|
+
* **`create.after` remembers the row** — a sign-in link or code about to be sent, OAuth state, or a wrong
|
|
1525
|
+
* code re-created with one more attempt counted; `../ledger/record.ts` tells them apart by what follows.
|
|
1526
|
+
* **`delete.before` remembers the row about to be consumed**, and changes nothing: it returns nothing, so it
|
|
1527
|
+
* never vetoes, and it is not a `delete.after` because claiming a verification removal the way
|
|
1528
|
+
* `claimedDelete` does would delete the row before the consume could read it.
|
|
1529
|
+
*/
|
|
1530
|
+
verification: {
|
|
1531
|
+
create: {
|
|
1532
|
+
after: (verification: {
|
|
1533
|
+
id: string;
|
|
1534
|
+
createdAt: Date;
|
|
1535
|
+
updatedAt: Date;
|
|
1536
|
+
value: string;
|
|
1537
|
+
expiresAt: Date;
|
|
1538
|
+
identifier: string;
|
|
1539
|
+
} & Record<string, unknown>, ctx: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
1540
|
+
};
|
|
1541
|
+
delete: {
|
|
1542
|
+
before: (verification: {
|
|
1543
|
+
id: string;
|
|
1544
|
+
createdAt: Date;
|
|
1545
|
+
updatedAt: Date;
|
|
1546
|
+
value: string;
|
|
1547
|
+
expiresAt: Date;
|
|
1548
|
+
identifier: string;
|
|
1549
|
+
} & Record<string, unknown>, ctx: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
1550
|
+
};
|
|
1551
|
+
};
|
|
1452
1552
|
user: {
|
|
1453
1553
|
create: {
|
|
1454
1554
|
before: (user: {
|
|
@@ -1590,6 +1690,39 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
1590
1690
|
authenticatedAt: Date | null;
|
|
1591
1691
|
};
|
|
1592
1692
|
}>;
|
|
1693
|
+
/**
|
|
1694
|
+
* Stamp the sign-in link or code this session was made from as used (#829), and name the account a
|
|
1695
|
+
* sign-up just created. Only a row consumed earlier in this same request is stamped, so a token
|
|
1696
|
+
* refresh, an OAuth callback and every other session stamp nothing — see `../ledger/record.ts`.
|
|
1697
|
+
* After, because the session exists by now: a sign-in the `before` above refused stamps nothing.
|
|
1698
|
+
*/
|
|
1699
|
+
after: (session: {
|
|
1700
|
+
id: string;
|
|
1701
|
+
createdAt: Date;
|
|
1702
|
+
updatedAt: Date;
|
|
1703
|
+
userId: string;
|
|
1704
|
+
expiresAt: Date;
|
|
1705
|
+
token: string;
|
|
1706
|
+
ipAddress?: string | null | undefined;
|
|
1707
|
+
userAgent?: string | null | undefined;
|
|
1708
|
+
} & Record<string, unknown>, ctx: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
1709
|
+
};
|
|
1710
|
+
update: {
|
|
1711
|
+
/**
|
|
1712
|
+
* The activity clock again, for a session that stays open. Better Auth slides a session forward in place
|
|
1713
|
+
* once `updateAge` has passed, and that refresh is an update, never a create, so the hook above never
|
|
1714
|
+
* sees it. Without this, signing out after weeks of use on one session would read as weeks idle.
|
|
1715
|
+
*/
|
|
1716
|
+
after: (session: {
|
|
1717
|
+
id: string;
|
|
1718
|
+
createdAt: Date;
|
|
1719
|
+
updatedAt: Date;
|
|
1720
|
+
userId: string;
|
|
1721
|
+
expiresAt: Date;
|
|
1722
|
+
token: string;
|
|
1723
|
+
ipAddress?: string | null | undefined;
|
|
1724
|
+
userAgent?: string | null | undefined;
|
|
1725
|
+
} & Record<string, unknown>) => Promise<void>;
|
|
1593
1726
|
};
|
|
1594
1727
|
/**
|
|
1595
1728
|
* Tell whoever keyed state on this session that it has gone, and record that it did.
|
|
@@ -1683,6 +1816,11 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
1683
1816
|
readonly required: false;
|
|
1684
1817
|
readonly input: false;
|
|
1685
1818
|
};
|
|
1819
|
+
readonly lastActiveAt: {
|
|
1820
|
+
readonly type: "number";
|
|
1821
|
+
readonly required: false;
|
|
1822
|
+
readonly input: false;
|
|
1823
|
+
};
|
|
1686
1824
|
readonly locale: {
|
|
1687
1825
|
readonly type: "string";
|
|
1688
1826
|
readonly required: false;
|
|
@@ -1789,11 +1927,11 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
1789
1927
|
handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
|
|
1790
1928
|
}[];
|
|
1791
1929
|
};
|
|
1792
|
-
options: import("better-auth/plugins
|
|
1930
|
+
options: import("better-auth/plugins").BearerOptions | undefined;
|
|
1793
1931
|
}, {
|
|
1794
1932
|
id: "jwt";
|
|
1795
1933
|
version: string;
|
|
1796
|
-
options: NoInfer<import("better-auth/plugins
|
|
1934
|
+
options: NoInfer<import("better-auth/plugins").JwtOptions>;
|
|
1797
1935
|
init(ctx: import("better-auth").AuthContext): {
|
|
1798
1936
|
context: {
|
|
1799
1937
|
sessionConfig: {
|
|
@@ -1944,7 +2082,7 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
1944
2082
|
$Infer: {
|
|
1945
2083
|
body: {
|
|
1946
2084
|
payload: import("better-auth").JWTPayload;
|
|
1947
|
-
overrideOptions?: import("better-auth/plugins
|
|
2085
|
+
overrideOptions?: import("better-auth/plugins").JwtOptions | undefined;
|
|
1948
2086
|
};
|
|
1949
2087
|
};
|
|
1950
2088
|
};
|
|
@@ -2122,7 +2260,7 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
2122
2260
|
window: number;
|
|
2123
2261
|
max: number;
|
|
2124
2262
|
}[];
|
|
2125
|
-
options: import("better-auth/plugins
|
|
2263
|
+
options: import("better-auth/plugins").MagicLinkOptions;
|
|
2126
2264
|
}, {
|
|
2127
2265
|
id: "email-otp";
|
|
2128
2266
|
version: string;
|
|
@@ -2649,7 +2787,7 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
|
|
|
2649
2787
|
window: number;
|
|
2650
2788
|
max: number;
|
|
2651
2789
|
})[];
|
|
2652
|
-
options: import("better-auth/plugins
|
|
2790
|
+
options: import("better-auth/plugins").EmailOTPOptions;
|
|
2653
2791
|
$ERROR_CODES: {
|
|
2654
2792
|
OTP_EXPIRED: import("better-auth").RawError<"OTP_EXPIRED">;
|
|
2655
2793
|
INVALID_OTP: import("better-auth").RawError<"INVALID_OTP">;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/instance/auth.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAEnE,OAAO,EAAE,KAAK,gBAAgB,EAAc,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAUtD"}
|
package/dist/instance/auth.js
CHANGED
|
@@ -5,7 +5,9 @@ import { claimedDelete, markSessionEnded, messageDeliveryDuring, sessionEndedDur
|
|
|
5
5
|
import { KIT_SESSION_FIELDS, KIT_USER_FIELDS } from "../data/kitFields.js";
|
|
6
6
|
import { parseDeviceMeta, registerDevice } from "../device/registry.js";
|
|
7
7
|
import "../http/providerFreshness.js";
|
|
8
|
-
import {
|
|
8
|
+
import { verificationLedger } from "../ledger/record.js";
|
|
9
|
+
import { admitsDeletionSignIn, lifecycleRefusalFor } from "../lifecycle/enforce.js";
|
|
10
|
+
import { recordActivity } from "../lifecycle/inactivity.js";
|
|
9
11
|
import { refuseUnsafeProfile, sanitizeProfile } from "../profile/profile.js";
|
|
10
12
|
import { defaultGithubUserInfo } from "./githubUserInfo.js";
|
|
11
13
|
import { microsoftProfileToUser } from "./microsoftEmail.js";
|
|
@@ -184,6 +186,7 @@ function callerOf(ctx) {
|
|
|
184
186
|
* UUIDs; rate limiting is durable (D1-backed) since memory limiting is per-isolate on Workers.
|
|
185
187
|
*/
|
|
186
188
|
function makeAuth(deps) {
|
|
189
|
+
const ledger = verificationLedger(deps.db);
|
|
187
190
|
return betterAuth({
|
|
188
191
|
appName: "Pithy",
|
|
189
192
|
baseURL: deps.baseURL,
|
|
@@ -202,6 +205,23 @@ function makeAuth(deps) {
|
|
|
202
205
|
} },
|
|
203
206
|
onAPIError: { throw: true },
|
|
204
207
|
databaseHooks: {
|
|
208
|
+
/**
|
|
209
|
+
* The verification ledger's two hooks on Better Auth's own verification rows (#829).
|
|
210
|
+
*
|
|
211
|
+
* **`create.after` remembers the row** — a sign-in link or code about to be sent, OAuth state, or a wrong
|
|
212
|
+
* code re-created with one more attempt counted; `../ledger/record.ts` tells them apart by what follows.
|
|
213
|
+
* **`delete.before` remembers the row about to be consumed**, and changes nothing: it returns nothing, so it
|
|
214
|
+
* never vetoes, and it is not a `delete.after` because claiming a verification removal the way
|
|
215
|
+
* `claimedDelete` does would delete the row before the consume could read it.
|
|
216
|
+
*/
|
|
217
|
+
verification: {
|
|
218
|
+
create: { after: async (verification, ctx) => {
|
|
219
|
+
await ledger.created(verification, ctx?.context);
|
|
220
|
+
} },
|
|
221
|
+
delete: { before: async (verification, ctx) => {
|
|
222
|
+
ledger.consuming(verification, ctx?.context);
|
|
223
|
+
} }
|
|
224
|
+
},
|
|
205
225
|
user: {
|
|
206
226
|
create: { before: async (user) => {
|
|
207
227
|
if (isUnverifiedSignup(user)) throw new APIError("FORBIDDEN", {
|
|
@@ -266,48 +286,70 @@ function makeAuth(deps) {
|
|
|
266
286
|
})
|
|
267
287
|
},
|
|
268
288
|
session: {
|
|
269
|
-
create: {
|
|
289
|
+
create: {
|
|
290
|
+
/**
|
|
291
|
+
* Stamp when this session's holder authenticated, and bind the session to its device.
|
|
292
|
+
*
|
|
293
|
+
* **`authenticatedAt` is stamped here and nowhere else.** A sign-in is the only event that is
|
|
294
|
+
* an authentication; `/token/rotate` carries the value forward through `createSession`'s
|
|
295
|
+
* override instead, which is why a rotated session keeps the original instant. A field
|
|
296
|
+
* `defaultValue` would have looked equivalent and is not: `getSessionDefaultFields` is spread
|
|
297
|
+
* into the row *after* the caller's override, so it would overwrite the carried value and
|
|
298
|
+
* silently restore the defect the column exists to fix (#558).
|
|
299
|
+
*
|
|
300
|
+
* A value already on the row is left alone — that is the rotation, passing its own.
|
|
301
|
+
*
|
|
302
|
+
* **Every other `createSession` is treated as an authentication, which is right for all of
|
|
303
|
+
* them the kit composes.** `better-auth/plugins/admin`'s `impersonateUser` would be the
|
|
304
|
+
* exception — an admin impersonating somebody would get a freshly-stamped session and could
|
|
305
|
+
* attach a provider to that account — but the kit composes no admin plugin, so it is a note
|
|
306
|
+
* for whoever does rather than a live path.
|
|
307
|
+
*
|
|
308
|
+
* Device binding only fires when the request carried device headers; a rotation passes
|
|
309
|
+
* `deviceId` by override for the same reason.
|
|
310
|
+
*/
|
|
311
|
+
before: async (session, ctx) => {
|
|
312
|
+
const refusal = await lifecycleRefusalFor(deps.db, session.userId, null, /* @__PURE__ */ new Date());
|
|
313
|
+
if (refusal && !admitsDeletionSignIn(refusal, ctx?.headers)) refuseSession(refusal, ctx);
|
|
314
|
+
const carried = session.authenticatedAt;
|
|
315
|
+
const authenticatedAt = carried !== void 0 ? carried : /* @__PURE__ */ new Date();
|
|
316
|
+
const meta = ctx?.headers ? parseDeviceMeta(ctx.headers) : void 0;
|
|
317
|
+
if (!meta) return { data: {
|
|
318
|
+
...session,
|
|
319
|
+
authenticatedAt
|
|
320
|
+
} };
|
|
321
|
+
await registerDevice(deps.db, meta, {
|
|
322
|
+
userId: session.userId,
|
|
323
|
+
lastIp: session.ipAddress ?? null,
|
|
324
|
+
now: /* @__PURE__ */ new Date()
|
|
325
|
+
});
|
|
326
|
+
return { data: {
|
|
327
|
+
...session,
|
|
328
|
+
deviceId: meta.id,
|
|
329
|
+
authenticatedAt
|
|
330
|
+
} };
|
|
331
|
+
},
|
|
332
|
+
/**
|
|
333
|
+
* Stamp the sign-in link or code this session was made from as used (#829), and name the account a
|
|
334
|
+
* sign-up just created. Only a row consumed earlier in this same request is stamped, so a token
|
|
335
|
+
* refresh, an OAuth callback and every other session stamp nothing — see `../ledger/record.ts`.
|
|
336
|
+
* After, because the session exists by now: a sign-in the `before` above refused stamps nothing.
|
|
337
|
+
*/
|
|
338
|
+
after: async (session, ctx) => {
|
|
339
|
+
await ledger.signedIn(ctx?.context, session.userId);
|
|
340
|
+
await recordActivity(deps.db, session.userId, /* @__PURE__ */ new Date()).catch(() => void 0);
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
update: {
|
|
270
344
|
/**
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
* an authentication; `/token/rotate` carries the value forward through `createSession`'s
|
|
275
|
-
* override instead, which is why a rotated session keeps the original instant. A field
|
|
276
|
-
* `defaultValue` would have looked equivalent and is not: `getSessionDefaultFields` is spread
|
|
277
|
-
* into the row *after* the caller's override, so it would overwrite the carried value and
|
|
278
|
-
* silently restore the defect the column exists to fix (#558).
|
|
279
|
-
*
|
|
280
|
-
* A value already on the row is left alone — that is the rotation, passing its own.
|
|
281
|
-
*
|
|
282
|
-
* **Every other `createSession` is treated as an authentication, which is right for all of
|
|
283
|
-
* them the kit composes.** `better-auth/plugins/admin`'s `impersonateUser` would be the
|
|
284
|
-
* exception — an admin impersonating somebody would get a freshly-stamped session and could
|
|
285
|
-
* attach a provider to that account — but the kit composes no admin plugin, so it is a note
|
|
286
|
-
* for whoever does rather than a live path.
|
|
287
|
-
*
|
|
288
|
-
* Device binding only fires when the request carried device headers; a rotation passes
|
|
289
|
-
* `deviceId` by override for the same reason.
|
|
345
|
+
* The activity clock again, for a session that stays open. Better Auth slides a session forward in place
|
|
346
|
+
* once `updateAge` has passed, and that refresh is an update, never a create, so the hook above never
|
|
347
|
+
* sees it. Without this, signing out after weeks of use on one session would read as weeks idle.
|
|
290
348
|
*/
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
if (
|
|
294
|
-
|
|
295
|
-
const authenticatedAt = carried !== void 0 ? carried : /* @__PURE__ */ new Date();
|
|
296
|
-
const meta = ctx?.headers ? parseDeviceMeta(ctx.headers) : void 0;
|
|
297
|
-
if (!meta) return { data: {
|
|
298
|
-
...session,
|
|
299
|
-
authenticatedAt
|
|
300
|
-
} };
|
|
301
|
-
await registerDevice(deps.db, meta, {
|
|
302
|
-
userId: session.userId,
|
|
303
|
-
lastIp: session.ipAddress ?? null,
|
|
304
|
-
now: /* @__PURE__ */ new Date()
|
|
305
|
-
});
|
|
306
|
-
return { data: {
|
|
307
|
-
...session,
|
|
308
|
-
deviceId: meta.id,
|
|
309
|
-
authenticatedAt
|
|
310
|
-
} };
|
|
349
|
+
after: async (session) => {
|
|
350
|
+
const userId = session?.userId;
|
|
351
|
+
if (typeof userId !== "string") return;
|
|
352
|
+
await recordActivity(deps.db, userId, /* @__PURE__ */ new Date()).catch(() => void 0);
|
|
311
353
|
} },
|
|
312
354
|
/**
|
|
313
355
|
* Tell whoever keyed state on this session that it has gone, and record that it did.
|
|
@@ -479,7 +521,10 @@ before: async (session, ctx) => {
|
|
|
479
521
|
const providers = socialProviders(deps);
|
|
480
522
|
return providers ? { socialProviders: providers } : {};
|
|
481
523
|
})(),
|
|
482
|
-
plugins: [...kitPlugins(
|
|
524
|
+
plugins: [...kitPlugins({
|
|
525
|
+
...deps,
|
|
526
|
+
ledger
|
|
527
|
+
}), ...deps.plugins]
|
|
483
528
|
});
|
|
484
529
|
}
|
|
485
530
|
//#endregion
|