@agent-native/core 0.158.5 → 0.158.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/mcp/screen-memory-stdio.d.ts +7 -7
- package/dist/notifications/routes.d.ts +3 -3
- package/dist/observability/routes.d.ts +1 -1
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/server/auth.js +242 -15
- package/dist/server/better-auth-instance.js +29 -1
- package/package.json +1 -1
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* Body: { json: any, fieldName?: string, type?: "map"|"array", requestSource?: string }
|
|
14
14
|
*/
|
|
15
15
|
export declare const postCollabJson: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
16
|
-
error: string;
|
|
17
16
|
ok?: undefined;
|
|
17
|
+
error: string;
|
|
18
18
|
} | {
|
|
19
19
|
error?: undefined;
|
|
20
20
|
ok: boolean;
|
|
@@ -137,13 +137,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
137
137
|
inputSchema: {
|
|
138
138
|
type: string;
|
|
139
139
|
properties: {
|
|
140
|
-
count?: undefined;
|
|
141
140
|
query?: undefined;
|
|
142
141
|
minutes?: undefined;
|
|
143
142
|
limit?: undefined;
|
|
144
143
|
clientHint?: undefined;
|
|
145
144
|
timestamp?: undefined;
|
|
146
145
|
chapterId?: undefined;
|
|
146
|
+
count?: undefined;
|
|
147
147
|
startAt?: undefined;
|
|
148
148
|
endAt?: undefined;
|
|
149
149
|
reason?: undefined;
|
|
@@ -159,7 +159,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
159
159
|
inputSchema: {
|
|
160
160
|
type: string;
|
|
161
161
|
properties: {
|
|
162
|
-
count?: undefined;
|
|
163
162
|
query: {
|
|
164
163
|
type: string;
|
|
165
164
|
description: string;
|
|
@@ -175,6 +174,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
175
174
|
clientHint?: undefined;
|
|
176
175
|
timestamp?: undefined;
|
|
177
176
|
chapterId?: undefined;
|
|
177
|
+
count?: undefined;
|
|
178
178
|
startAt?: undefined;
|
|
179
179
|
endAt?: undefined;
|
|
180
180
|
reason?: undefined;
|
|
@@ -190,7 +190,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
190
190
|
inputSchema: {
|
|
191
191
|
type: string;
|
|
192
192
|
properties: {
|
|
193
|
-
count?: undefined;
|
|
194
193
|
minutes: {
|
|
195
194
|
type: string;
|
|
196
195
|
description: string;
|
|
@@ -200,6 +199,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
200
199
|
clientHint?: undefined;
|
|
201
200
|
timestamp?: undefined;
|
|
202
201
|
chapterId?: undefined;
|
|
202
|
+
count?: undefined;
|
|
203
203
|
startAt?: undefined;
|
|
204
204
|
endAt?: undefined;
|
|
205
205
|
reason?: undefined;
|
|
@@ -216,7 +216,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
216
216
|
type: string;
|
|
217
217
|
required: string[];
|
|
218
218
|
properties: {
|
|
219
|
-
count?: undefined;
|
|
220
219
|
query: {
|
|
221
220
|
type: string;
|
|
222
221
|
description: string;
|
|
@@ -235,6 +234,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
235
234
|
};
|
|
236
235
|
timestamp?: undefined;
|
|
237
236
|
chapterId?: undefined;
|
|
237
|
+
count?: undefined;
|
|
238
238
|
startAt?: undefined;
|
|
239
239
|
endAt?: undefined;
|
|
240
240
|
reason?: undefined;
|
|
@@ -250,7 +250,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
250
250
|
type: string;
|
|
251
251
|
required: string[];
|
|
252
252
|
properties: {
|
|
253
|
-
count?: undefined;
|
|
254
253
|
query?: undefined;
|
|
255
254
|
minutes?: undefined;
|
|
256
255
|
limit?: undefined;
|
|
@@ -264,6 +263,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
264
263
|
description: string;
|
|
265
264
|
};
|
|
266
265
|
chapterId?: undefined;
|
|
266
|
+
count?: undefined;
|
|
267
267
|
startAt?: undefined;
|
|
268
268
|
endAt?: undefined;
|
|
269
269
|
includeMicrophone?: undefined;
|
|
@@ -314,13 +314,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
314
314
|
type: string;
|
|
315
315
|
required: string[];
|
|
316
316
|
properties: {
|
|
317
|
-
count?: undefined;
|
|
318
317
|
query?: undefined;
|
|
319
318
|
minutes?: undefined;
|
|
320
319
|
limit?: undefined;
|
|
321
320
|
clientHint?: undefined;
|
|
322
321
|
timestamp?: undefined;
|
|
323
322
|
chapterId?: undefined;
|
|
323
|
+
count?: undefined;
|
|
324
324
|
startAt: {
|
|
325
325
|
type: string;
|
|
326
326
|
description: string;
|
|
@@ -349,13 +349,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
|
|
|
349
349
|
type: string;
|
|
350
350
|
required: string[];
|
|
351
351
|
properties: {
|
|
352
|
-
count?: undefined;
|
|
353
352
|
query?: undefined;
|
|
354
353
|
minutes?: undefined;
|
|
355
354
|
limit?: undefined;
|
|
356
355
|
clientHint?: undefined;
|
|
357
356
|
timestamp?: undefined;
|
|
358
357
|
chapterId?: undefined;
|
|
358
|
+
count?: undefined;
|
|
359
359
|
startAt?: undefined;
|
|
360
360
|
endAt?: undefined;
|
|
361
361
|
reason?: undefined;
|
|
@@ -16,18 +16,18 @@ export declare function createNotificationsHandler(): import("h3").EventHandlerW
|
|
|
16
16
|
error?: undefined;
|
|
17
17
|
ok?: undefined;
|
|
18
18
|
} | {
|
|
19
|
-
count?: undefined;
|
|
20
19
|
updated: number;
|
|
21
20
|
error?: undefined;
|
|
22
21
|
ok?: undefined;
|
|
23
|
-
} | {
|
|
24
22
|
count?: undefined;
|
|
23
|
+
} | {
|
|
25
24
|
updated?: undefined;
|
|
26
25
|
error: string;
|
|
27
26
|
ok?: undefined;
|
|
28
|
-
} | {
|
|
29
27
|
count?: undefined;
|
|
28
|
+
} | {
|
|
30
29
|
updated?: undefined;
|
|
31
30
|
error?: undefined;
|
|
32
31
|
ok: boolean;
|
|
32
|
+
count?: undefined;
|
|
33
33
|
}>>;
|
|
@@ -48,8 +48,8 @@ export declare function handleUpdateResource(event: any): Promise<import("./stor
|
|
|
48
48
|
}>;
|
|
49
49
|
/** DELETE /_agent-native/resources/:id — delete a resource */
|
|
50
50
|
export declare function handleDeleteResource(event: any): Promise<{
|
|
51
|
-
error: string;
|
|
52
51
|
ok?: undefined;
|
|
52
|
+
error: string;
|
|
53
53
|
} | {
|
|
54
54
|
error?: undefined;
|
|
55
55
|
ok: boolean;
|
package/dist/server/auth.js
CHANGED
|
@@ -1538,6 +1538,162 @@ function escapeHtmlAttr(value) {
|
|
|
1538
1538
|
const DESKTOP_MAGIC_LINK_CALLBACK_PATH = "/_agent-native/auth/magic-link/desktop-callback";
|
|
1539
1539
|
const DESKTOP_MAGIC_LINK_LANDING_PATH = "/_agent-native/auth/magic-link/desktop-landing";
|
|
1540
1540
|
const BETTER_AUTH_MAGIC_LINK_VERIFY_PATH = "/_agent-native/auth/ba/magic-link/verify";
|
|
1541
|
+
function magicLinkDigest(value) {
|
|
1542
|
+
return crypto.createHash("sha256").update(value).digest("hex").slice(0, 16);
|
|
1543
|
+
}
|
|
1544
|
+
function magicLinkStoredIdentifier(token) {
|
|
1545
|
+
return crypto.createHash("sha256").update(token).digest("base64url");
|
|
1546
|
+
}
|
|
1547
|
+
function redactMagicLinkUrl(value, baseURL) {
|
|
1548
|
+
try {
|
|
1549
|
+
const url = new URL(value, baseURL);
|
|
1550
|
+
for (const key of ["token", "flow_id", "verifier", "state"]) {
|
|
1551
|
+
if (url.searchParams.has(key))
|
|
1552
|
+
url.searchParams.set(key, "[redacted]");
|
|
1553
|
+
}
|
|
1554
|
+
for (const key of [
|
|
1555
|
+
"callbackURL",
|
|
1556
|
+
"newUserCallbackURL",
|
|
1557
|
+
"errorCallbackURL",
|
|
1558
|
+
]) {
|
|
1559
|
+
const callback = url.searchParams.get(key);
|
|
1560
|
+
if (!callback)
|
|
1561
|
+
continue;
|
|
1562
|
+
try {
|
|
1563
|
+
const callbackURL = new URL(callback, url.origin);
|
|
1564
|
+
for (const nestedKey of ["flow_id", "verifier", "state"]) {
|
|
1565
|
+
if (callbackURL.searchParams.has(nestedKey)) {
|
|
1566
|
+
callbackURL.searchParams.set(nestedKey, "[redacted]");
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
url.searchParams.set(key, callbackURL.toString());
|
|
1570
|
+
}
|
|
1571
|
+
catch {
|
|
1572
|
+
url.searchParams.set(key, "[invalid]");
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
return `${url.pathname}${url.search}`;
|
|
1576
|
+
}
|
|
1577
|
+
catch {
|
|
1578
|
+
return "[invalid-url]";
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
function magicLinkRequestDetails(event, values, verificationURL) {
|
|
1582
|
+
const token = typeof values.token === "string" ? values.token.trim() : "";
|
|
1583
|
+
const callbackValue = typeof values.callbackURL === "string" ? values.callbackURL : "";
|
|
1584
|
+
let callback;
|
|
1585
|
+
try {
|
|
1586
|
+
callback = callbackValue
|
|
1587
|
+
? new URL(callbackValue, getOrigin(event))
|
|
1588
|
+
: undefined;
|
|
1589
|
+
}
|
|
1590
|
+
catch {
|
|
1591
|
+
callback = undefined;
|
|
1592
|
+
}
|
|
1593
|
+
return {
|
|
1594
|
+
requestMethod: getMethod(event),
|
|
1595
|
+
requestUrl: redactMagicLinkUrl(event.node?.req?.url ?? event.path ?? "", getOrigin(event)),
|
|
1596
|
+
verificationUrl: verificationURL
|
|
1597
|
+
? redactMagicLinkUrl(verificationURL.toString(), getOrigin(event))
|
|
1598
|
+
: undefined,
|
|
1599
|
+
verificationMethod: verificationURL ? "GET" : undefined,
|
|
1600
|
+
tokenPresent: Boolean(token),
|
|
1601
|
+
tokenLength: token.length || undefined,
|
|
1602
|
+
tokenDigest: token ? magicLinkDigest(token) : undefined,
|
|
1603
|
+
expectedStoredIdentifierPrefix: token
|
|
1604
|
+
? magicLinkStoredIdentifier(token).slice(0, 16)
|
|
1605
|
+
: undefined,
|
|
1606
|
+
callbackURLPresent: Boolean(callbackValue),
|
|
1607
|
+
callbackPath: callback?.pathname,
|
|
1608
|
+
hasFlowId: Boolean(callback?.searchParams.get("flow_id")),
|
|
1609
|
+
hasVerifier: Boolean(callback?.searchParams.get("verifier")),
|
|
1610
|
+
hasState: Boolean(callback?.searchParams.get("state") || values.state),
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
async function inspectMagicLinkVerification(auth, token) {
|
|
1614
|
+
const storedIdentifier = magicLinkStoredIdentifier(token);
|
|
1615
|
+
try {
|
|
1616
|
+
const context = await auth.$context;
|
|
1617
|
+
const findVerificationValue = context?.internalAdapter?.findVerificationValue;
|
|
1618
|
+
if (typeof findVerificationValue !== "function") {
|
|
1619
|
+
return {
|
|
1620
|
+
lookup: "adapter-unavailable",
|
|
1621
|
+
lookupKeyPrefix: storedIdentifier.slice(0, 16),
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
const record = await findVerificationValue(storedIdentifier);
|
|
1625
|
+
if (!record) {
|
|
1626
|
+
return {
|
|
1627
|
+
lookup: "absent",
|
|
1628
|
+
lookupKeyPrefix: storedIdentifier.slice(0, 16),
|
|
1629
|
+
};
|
|
1630
|
+
}
|
|
1631
|
+
const expiresAt = new Date(String(record.expiresAt ?? ""));
|
|
1632
|
+
const expiryState = Number.isFinite(expiresAt.getTime())
|
|
1633
|
+
? expiresAt.getTime() <= Date.now()
|
|
1634
|
+
? "expired"
|
|
1635
|
+
: "valid"
|
|
1636
|
+
: "invalid-expiry";
|
|
1637
|
+
return {
|
|
1638
|
+
lookup: "present",
|
|
1639
|
+
lookupKeyPrefix: storedIdentifier.slice(0, 16),
|
|
1640
|
+
expiryState,
|
|
1641
|
+
expiresAt: Number.isFinite(expiresAt.getTime())
|
|
1642
|
+
? expiresAt.toISOString()
|
|
1643
|
+
: undefined,
|
|
1644
|
+
valuePresent: "value" in record,
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
catch (error) {
|
|
1648
|
+
return {
|
|
1649
|
+
lookup: "lookup-error",
|
|
1650
|
+
lookupKeyPrefix: storedIdentifier.slice(0, 16),
|
|
1651
|
+
errorType: error instanceof Error ? error.constructor.name : "unknown",
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
function logMagicLinkDebug(event, phase, details = {}) {
|
|
1656
|
+
console.info("[agent-native][magic-link]", {
|
|
1657
|
+
phase,
|
|
1658
|
+
app: getOAuthStateAppId(),
|
|
1659
|
+
agentNativeDesktop: /AgentNativeDesktop/i.test(getHeader(event, "user-agent") || ""),
|
|
1660
|
+
...details,
|
|
1661
|
+
});
|
|
1662
|
+
}
|
|
1663
|
+
function magicLinkResponseError(response, baseURL) {
|
|
1664
|
+
const location = response.headers.get("location");
|
|
1665
|
+
if (!location)
|
|
1666
|
+
return undefined;
|
|
1667
|
+
try {
|
|
1668
|
+
return new URL(location, baseURL).searchParams.get("error") || undefined;
|
|
1669
|
+
// coercion-ok: a malformed redirect cannot contain a diagnostic error code.
|
|
1670
|
+
}
|
|
1671
|
+
catch {
|
|
1672
|
+
return undefined;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
function logMagicLinkVerificationResponse(event, source, response, preConsume) {
|
|
1676
|
+
const error = magicLinkResponseError(response, getOrigin(event));
|
|
1677
|
+
const invalidToken = error === "INVALID_TOKEN";
|
|
1678
|
+
logMagicLinkDebug(event, "verify-response", {
|
|
1679
|
+
source,
|
|
1680
|
+
responseStatus: response.status,
|
|
1681
|
+
responseLocation: redactMagicLinkUrl(response.headers.get("location") || "", getOrigin(event)),
|
|
1682
|
+
producer: invalidToken ? "better-auth.magic-link.verify" : undefined,
|
|
1683
|
+
reason: invalidToken ? "consumeVerificationValue returned null" : undefined,
|
|
1684
|
+
preConsume,
|
|
1685
|
+
classification: invalidToken
|
|
1686
|
+
? preConsume?.lookup === "present" && preConsume.expiryState === "valid"
|
|
1687
|
+
? "valid-row-before-consume"
|
|
1688
|
+
: preConsume?.lookup === "present" &&
|
|
1689
|
+
preConsume.expiryState === "expired"
|
|
1690
|
+
? "expired-row"
|
|
1691
|
+
: preConsume?.lookup === "absent"
|
|
1692
|
+
? "row-absent-before-consume"
|
|
1693
|
+
: "unresolved"
|
|
1694
|
+
: undefined,
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1541
1697
|
function desktopMagicLinkVerificationUrl(event, values) {
|
|
1542
1698
|
const value = (key) => typeof values[key] === "string" ? values[key] : "";
|
|
1543
1699
|
const token = value("token").trim();
|
|
@@ -3088,23 +3244,51 @@ async function mountBetterAuthRoutes(app, options) {
|
|
|
3088
3244
|
// commonly prefetch GET links, while Better Auth consumes a magic-link token
|
|
3089
3245
|
// on the first verification GET. The explicit form action below is the only
|
|
3090
3246
|
// request that reaches Better Auth's consuming verification endpoint.
|
|
3091
|
-
app.use(DESKTOP_MAGIC_LINK_LANDING_PATH, defineEventHandler((event) => {
|
|
3247
|
+
app.use(DESKTOP_MAGIC_LINK_LANDING_PATH, defineEventHandler(async (event) => {
|
|
3092
3248
|
if (getMethod(event) === "POST") {
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
headers: {
|
|
3102
|
-
"cache-control": "no-store",
|
|
3103
|
-
location: verificationURL.toString(),
|
|
3104
|
-
"referrer-policy": "no-referrer",
|
|
3105
|
-
},
|
|
3249
|
+
const body = await readBody(event);
|
|
3250
|
+
const verificationURL = desktopMagicLinkVerificationUrl(event, body);
|
|
3251
|
+
const requestDetails = magicLinkRequestDetails(event, body, verificationURL);
|
|
3252
|
+
if (!verificationURL) {
|
|
3253
|
+
logMagicLinkDebug(event, "verify-rejected-before-better-auth", {
|
|
3254
|
+
source: "desktop-landing",
|
|
3255
|
+
...requestDetails,
|
|
3256
|
+
reason: "invalid-desktop-verification-url",
|
|
3106
3257
|
});
|
|
3258
|
+
setResponseStatus(event, 400);
|
|
3259
|
+
return { error: "Invalid desktop magic-link" };
|
|
3260
|
+
}
|
|
3261
|
+
const token = typeof body.token === "string" ? body.token.trim() : "";
|
|
3262
|
+
const preConsume = await inspectMagicLinkVerification(auth, token);
|
|
3263
|
+
logMagicLinkDebug(event, "verify-request", {
|
|
3264
|
+
source: "desktop-landing",
|
|
3265
|
+
...requestDetails,
|
|
3266
|
+
preConsume,
|
|
3107
3267
|
});
|
|
3268
|
+
// Verify inside the same request that received the explicit user
|
|
3269
|
+
// confirmation. A browser redirect would create a second network
|
|
3270
|
+
// hop where link scanners, redirect handling, or a fresh serverless
|
|
3271
|
+
// request could consume or lose the one-time token before the
|
|
3272
|
+
// desktop callback sees the Better Auth session cookie.
|
|
3273
|
+
try {
|
|
3274
|
+
const response = await auth.handler(new Request(verificationURL, {
|
|
3275
|
+
method: "GET",
|
|
3276
|
+
headers: event.headers,
|
|
3277
|
+
}));
|
|
3278
|
+
if (response instanceof Response) {
|
|
3279
|
+
logMagicLinkVerificationResponse(event, "desktop-landing", response, preConsume);
|
|
3280
|
+
}
|
|
3281
|
+
return response;
|
|
3282
|
+
}
|
|
3283
|
+
catch (error) {
|
|
3284
|
+
logMagicLinkDebug(event, "verify-exception", {
|
|
3285
|
+
source: "desktop-landing",
|
|
3286
|
+
...requestDetails,
|
|
3287
|
+
preConsume,
|
|
3288
|
+
errorType: error instanceof Error ? error.constructor.name : "unknown",
|
|
3289
|
+
});
|
|
3290
|
+
throw error;
|
|
3291
|
+
}
|
|
3108
3292
|
}
|
|
3109
3293
|
if (!isReadMethod(event)) {
|
|
3110
3294
|
setResponseStatus(event, 405);
|
|
@@ -3157,6 +3341,17 @@ async function mountBetterAuthRoutes(app, options) {
|
|
|
3157
3341
|
message: AUTH_MAGIC_LINK_FALLBACK,
|
|
3158
3342
|
code: code || "callback_error",
|
|
3159
3343
|
});
|
|
3344
|
+
logMagicLinkDebug(event, "callback-error", {
|
|
3345
|
+
source: "desktop-callback",
|
|
3346
|
+
flow: oauthDebugFlowId(flowId),
|
|
3347
|
+
callbackError: code || "callback_error",
|
|
3348
|
+
producer: code === "INVALID_TOKEN"
|
|
3349
|
+
? "better-auth.magic-link.verify"
|
|
3350
|
+
: "desktop-callback",
|
|
3351
|
+
reason: code === "INVALID_TOKEN"
|
|
3352
|
+
? "upstream-verifier-reported-invalid-token"
|
|
3353
|
+
: "callback-carried-error",
|
|
3354
|
+
});
|
|
3160
3355
|
logGoogleOAuthDebug(event, "magic-link-callback-error", {
|
|
3161
3356
|
flowId,
|
|
3162
3357
|
message: callbackError,
|
|
@@ -3224,11 +3419,27 @@ async function mountBetterAuthRoutes(app, options) {
|
|
|
3224
3419
|
const isSendVerificationEmail = reqPath.includes("send-verification-email") &&
|
|
3225
3420
|
getMethod(event) === "POST";
|
|
3226
3421
|
const isMagicLinkRequest = reqPath.includes("/sign-in/magic-link") && getMethod(event) === "POST";
|
|
3422
|
+
const isMagicLinkVerification = reqPath.includes("/magic-link/verify") && getMethod(event) === "GET";
|
|
3227
3423
|
const isSignOut = reqPath.includes("sign-out") && getMethod(event) === "POST";
|
|
3228
3424
|
if (isSignOut)
|
|
3229
3425
|
optOutOfAuthDisabledSession(event);
|
|
3230
3426
|
const authRequest = toWebRequest(event);
|
|
3231
3427
|
let requestForAuth = authRequest;
|
|
3428
|
+
let magicLinkPreConsume;
|
|
3429
|
+
if (isMagicLinkVerification) {
|
|
3430
|
+
const verificationURL = new URL(authRequest.url);
|
|
3431
|
+
const values = Object.fromEntries(verificationURL.searchParams.entries());
|
|
3432
|
+
const requestDetails = magicLinkRequestDetails(event, values, verificationURL);
|
|
3433
|
+
const token = typeof values.token === "string" ? values.token.trim() : "";
|
|
3434
|
+
magicLinkPreConsume = token
|
|
3435
|
+
? await inspectMagicLinkVerification(auth, token)
|
|
3436
|
+
: undefined;
|
|
3437
|
+
logMagicLinkDebug(event, "verify-request", {
|
|
3438
|
+
source: "better-auth-catch-all",
|
|
3439
|
+
...requestDetails,
|
|
3440
|
+
preConsume: magicLinkPreConsume,
|
|
3441
|
+
});
|
|
3442
|
+
}
|
|
3232
3443
|
// Better Auth is also reachable directly, outside the legacy login
|
|
3233
3444
|
// wrapper. Check its password endpoints before handing the request to
|
|
3234
3445
|
// Better Auth so an org policy cannot be bypassed through the raw API.
|
|
@@ -3330,10 +3541,26 @@ async function mountBetterAuthRoutes(app, options) {
|
|
|
3330
3541
|
// validation error.
|
|
3331
3542
|
}
|
|
3332
3543
|
}
|
|
3333
|
-
let response
|
|
3544
|
+
let response;
|
|
3545
|
+
try {
|
|
3546
|
+
response = await auth.handler(requestForAuth);
|
|
3547
|
+
}
|
|
3548
|
+
catch (error) {
|
|
3549
|
+
if (isMagicLinkVerification) {
|
|
3550
|
+
logMagicLinkDebug(event, "verify-exception", {
|
|
3551
|
+
source: "better-auth-catch-all",
|
|
3552
|
+
errorType: error instanceof Error ? error.constructor.name : "unknown",
|
|
3553
|
+
preConsume: magicLinkPreConsume,
|
|
3554
|
+
});
|
|
3555
|
+
}
|
|
3556
|
+
throw error;
|
|
3557
|
+
}
|
|
3334
3558
|
const isResponse = response != null &&
|
|
3335
3559
|
typeof response.status === "number" &&
|
|
3336
3560
|
typeof response.headers?.get === "function";
|
|
3561
|
+
if (isMagicLinkVerification && isResponse) {
|
|
3562
|
+
logMagicLinkVerificationResponse(event, "better-auth-catch-all", response, magicLinkPreConsume);
|
|
3563
|
+
}
|
|
3337
3564
|
if (isResponse && response.status >= 400) {
|
|
3338
3565
|
// The direct Better Auth surface is also reachable from the browser,
|
|
3339
3566
|
// so wrapper-route sanitization alone is not enough to keep adapter
|
|
@@ -1158,7 +1158,35 @@ async function createBetterAuthInstance(config) {
|
|
|
1158
1158
|
storeToken: "hashed",
|
|
1159
1159
|
rateLimit: { window: 60, max: 5 },
|
|
1160
1160
|
disableSignUp,
|
|
1161
|
-
sendMagicLink: async ({ email, url }) => {
|
|
1161
|
+
sendMagicLink: async ({ email, url, token }) => {
|
|
1162
|
+
let urlPath;
|
|
1163
|
+
let urlQueryKeys;
|
|
1164
|
+
try {
|
|
1165
|
+
const parsedURL = new URL(url);
|
|
1166
|
+
urlPath = parsedURL.pathname;
|
|
1167
|
+
urlQueryKeys = [...parsedURL.searchParams.keys()].sort();
|
|
1168
|
+
}
|
|
1169
|
+
catch {
|
|
1170
|
+
// coercion-ok: diagnostics must never make email delivery fail.
|
|
1171
|
+
// Better Auth owns URL construction; keep diagnostics non-fatal.
|
|
1172
|
+
}
|
|
1173
|
+
if (typeof token === "string") {
|
|
1174
|
+
console.info("[agent-native][magic-link]", {
|
|
1175
|
+
phase: "issued",
|
|
1176
|
+
tokenDigest: crypto
|
|
1177
|
+
.createHash("sha256")
|
|
1178
|
+
.update(token)
|
|
1179
|
+
.digest("hex")
|
|
1180
|
+
.slice(0, 16),
|
|
1181
|
+
expectedStoredIdentifierPrefix: crypto
|
|
1182
|
+
.createHash("sha256")
|
|
1183
|
+
.update(token)
|
|
1184
|
+
.digest("base64url")
|
|
1185
|
+
.slice(0, 16),
|
|
1186
|
+
urlPath,
|
|
1187
|
+
urlQueryKeys,
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1162
1190
|
const appBasePath = (process.env.VITE_APP_BASE_PATH ||
|
|
1163
1191
|
process.env.APP_BASE_PATH ||
|
|
1164
1192
|
"").replace(/\/$/, "");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-native/core",
|
|
3
|
-
"version": "0.158.
|
|
3
|
+
"version": "0.158.7",
|
|
4
4
|
"description": "Framework for agent-native application development — where AI agents and UI share SQL state, actions, and context",
|
|
5
5
|
"homepage": "https://github.com/BuilderIO/agent-native#readme",
|
|
6
6
|
"bugs": {
|