better-auth 1.6.30 → 1.6.32
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/api/dispatch.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { runWithEndpointContext } from "@better-auth/core/context";
|
|
|
4
4
|
import { shouldPublishLog } from "@better-auth/core/env";
|
|
5
5
|
import { APIError } from "@better-auth/core/error";
|
|
6
6
|
import { createDefu } from "defu";
|
|
7
|
-
import { ATTR_CONTEXT, ATTR_HOOK_TYPE, ATTR_HTTP_ROUTE, ATTR_OPERATION_ID,
|
|
7
|
+
import { ATTR_CONTEXT, ATTR_HOOK_TYPE, ATTR_HTTP_ROUTE, ATTR_OPERATION_ID, createWithSpan } from "@better-auth/core/instrumentation";
|
|
8
8
|
import { kAPIErrorHeaderSymbol, toResponse } from "better-call";
|
|
9
9
|
//#region src/api/dispatch.ts
|
|
10
10
|
const defuReplaceArrays = createDefu((obj, key, value) => {
|
|
@@ -62,6 +62,7 @@ function mergeAPIErrorHeaders(error) {
|
|
|
62
62
|
return headers;
|
|
63
63
|
}
|
|
64
64
|
async function runBeforeHooks(context, hooks, endpoint, operationId) {
|
|
65
|
+
const withSpan = createWithSpan(context.context.options);
|
|
65
66
|
let modifiedContext = {};
|
|
66
67
|
for (const hook of hooks) {
|
|
67
68
|
let matched = false;
|
|
@@ -105,6 +106,7 @@ async function runBeforeHooks(context, hooks, endpoint, operationId) {
|
|
|
105
106
|
return { context: modifiedContext };
|
|
106
107
|
}
|
|
107
108
|
async function runAfterHooks(context, hooks, endpoint, operationId) {
|
|
109
|
+
const withSpan = createWithSpan(context.context.options);
|
|
108
110
|
for (const hook of hooks) {
|
|
109
111
|
if (!hook.matcher(context)) continue;
|
|
110
112
|
const hookSource = hooksSourceWeakMap.get(hook.handler) ?? "unknown";
|
|
@@ -182,6 +184,7 @@ function getHooks(authContext) {
|
|
|
182
184
|
* @param input Input context whose `context` is an already-resolved `AuthContext`.
|
|
183
185
|
*/
|
|
184
186
|
async function dispatchAuthEndpoint(endpoint, input) {
|
|
187
|
+
const withSpan = createWithSpan(input.context.options);
|
|
185
188
|
const operationId = input.operationId ?? getOperationId(endpoint);
|
|
186
189
|
const route = endpoint.path ?? "/:virtual";
|
|
187
190
|
const endpointMethod = endpoint.options?.method;
|
package/dist/api/index.mjs
CHANGED
|
@@ -21,7 +21,7 @@ import { toAuthEndpoints } from "./to-auth-endpoints.mjs";
|
|
|
21
21
|
import { logger } from "@better-auth/core/env";
|
|
22
22
|
import { APIError } from "@better-auth/core/error";
|
|
23
23
|
import { getIp } from "@better-auth/core/utils/ip";
|
|
24
|
-
import { ATTR_CONTEXT, ATTR_HOOK_TYPE, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE,
|
|
24
|
+
import { ATTR_CONTEXT, ATTR_HOOK_TYPE, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, createWithSpan } from "@better-auth/core/instrumentation";
|
|
25
25
|
import { normalizePathname } from "@better-auth/core/utils/url";
|
|
26
26
|
import { createRouter } from "better-call";
|
|
27
27
|
import { createAuthEndpoint, createAuthMiddleware, optionsMiddleware } from "@better-auth/core/api";
|
|
@@ -82,6 +82,7 @@ To resolve this, you can:
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
function getEndpoints(ctx, options) {
|
|
85
|
+
const withSpan = createWithSpan(options);
|
|
85
86
|
const pluginEndpoints = options.plugins?.reduce((acc, plugin) => {
|
|
86
87
|
return {
|
|
87
88
|
...acc,
|
|
@@ -148,6 +149,7 @@ function getEndpoints(ctx, options) {
|
|
|
148
149
|
};
|
|
149
150
|
}
|
|
150
151
|
const router = (ctx, options) => {
|
|
152
|
+
const withSpan = createWithSpan(options);
|
|
151
153
|
const { api, middlewares } = getEndpoints(ctx, options);
|
|
152
154
|
const basePath = new URL(ctx.baseURL).pathname;
|
|
153
155
|
return createRouter(api, {
|
package/dist/db/with-hooks.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getCurrentAdapter, getCurrentAuthContext, queueAfterTransactionHook } from "@better-auth/core/context";
|
|
2
|
-
import { ATTR_CONTEXT, ATTR_DB_COLLECTION_NAME, ATTR_HOOK_TYPE,
|
|
2
|
+
import { ATTR_CONTEXT, ATTR_DB_COLLECTION_NAME, ATTR_HOOK_TYPE, createWithSpan } from "@better-auth/core/instrumentation";
|
|
3
3
|
//#region src/db/with-hooks.ts
|
|
4
4
|
function getWithHooks(adapter, ctx) {
|
|
5
|
+
const withSpan = createWithSpan(ctx.options);
|
|
5
6
|
const hooksEntries = ctx.hooks;
|
|
6
7
|
async function createWithHooks(data, model, customCreateFn) {
|
|
7
8
|
const context = await getCurrentAuthContext().catch(() => null);
|
package/dist/package.mjs
CHANGED
|
@@ -44,6 +44,7 @@ const captcha = (options) => ({
|
|
|
44
44
|
};
|
|
45
45
|
if (options.provider === Providers.CLOUDFLARE_TURNSTILE) return await cloudflareTurnstile({
|
|
46
46
|
...handlerParams,
|
|
47
|
+
logger: ctx.logger,
|
|
47
48
|
expectedAction: options.expectedAction,
|
|
48
49
|
allowedHostnames: options.allowedHostnames
|
|
49
50
|
});
|
|
@@ -3,7 +3,7 @@ import { CAPTCHA_VERIFY_TIMEOUT_MS } from "../constants.mjs";
|
|
|
3
3
|
import { EXTERNAL_ERROR_CODES, INTERNAL_ERROR_CODES } from "../error-codes.mjs";
|
|
4
4
|
import { betterFetch } from "@better-fetch/fetch";
|
|
5
5
|
//#region src/plugins/captcha/verify-handlers/cloudflare-turnstile.ts
|
|
6
|
-
const cloudflareTurnstile = async ({ siteVerifyURL, captchaResponse, secretKey, remoteIP, expectedAction, allowedHostnames }) => {
|
|
6
|
+
const cloudflareTurnstile = async ({ siteVerifyURL, captchaResponse, secretKey, logger, remoteIP, expectedAction, allowedHostnames }) => {
|
|
7
7
|
const response = await betterFetch(siteVerifyURL, {
|
|
8
8
|
method: "POST",
|
|
9
9
|
timeout: CAPTCHA_VERIFY_TIMEOUT_MS,
|
|
@@ -15,14 +15,33 @@ const cloudflareTurnstile = async ({ siteVerifyURL, captchaResponse, secretKey,
|
|
|
15
15
|
})
|
|
16
16
|
});
|
|
17
17
|
if (!response.data || response.error) throw new Error(INTERNAL_ERROR_CODES.SERVICE_UNAVAILABLE.message);
|
|
18
|
-
const verificationFailed = () =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const verificationFailed = (details) => {
|
|
19
|
+
logger.warn("Cloudflare Turnstile verification failed", {
|
|
20
|
+
provider: "cloudflare-turnstile",
|
|
21
|
+
...details
|
|
22
|
+
});
|
|
23
|
+
return middlewareResponse({
|
|
24
|
+
message: EXTERNAL_ERROR_CODES.VERIFICATION_FAILED.message,
|
|
25
|
+
code: EXTERNAL_ERROR_CODES.VERIFICATION_FAILED.code,
|
|
26
|
+
status: 403
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
if (!response.data.success) return verificationFailed({
|
|
30
|
+
reason: "siteverify_rejected",
|
|
31
|
+
errorCodes: response.data["error-codes"] ?? [],
|
|
32
|
+
...response.data.hostname && { hostname: response.data.hostname },
|
|
33
|
+
...response.data.action && { action: response.data.action }
|
|
34
|
+
});
|
|
35
|
+
if (expectedAction && response.data.action !== expectedAction) return verificationFailed({
|
|
36
|
+
reason: "action_mismatch",
|
|
37
|
+
expectedAction,
|
|
38
|
+
actualAction: response.data.action
|
|
39
|
+
});
|
|
40
|
+
if (allowedHostnames && allowedHostnames.length > 0 && !(response.data.hostname && allowedHostnames.includes(response.data.hostname))) return verificationFailed({
|
|
41
|
+
reason: "hostname_mismatch",
|
|
42
|
+
allowedHostnames,
|
|
43
|
+
actualHostname: response.data.hostname
|
|
22
44
|
});
|
|
23
|
-
if (!response.data.success) return verificationFailed();
|
|
24
|
-
if (expectedAction && response.data.action !== expectedAction) return verificationFailed();
|
|
25
|
-
if (allowedHostnames && allowedHostnames.length > 0 && !(response.data.hostname && allowedHostnames.includes(response.data.hostname))) return verificationFailed();
|
|
26
45
|
};
|
|
27
46
|
//#endregion
|
|
28
47
|
export { cloudflareTurnstile };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-auth",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.32",
|
|
4
4
|
"description": "The most comprehensive authentication framework for TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -489,13 +489,13 @@
|
|
|
489
489
|
"kysely": "^0.28.17 || ^0.29.0",
|
|
490
490
|
"nanostores": "^1.1.1",
|
|
491
491
|
"zod": "^4.3.6",
|
|
492
|
-
"@better-auth/core": "1.6.
|
|
493
|
-
"@better-auth/drizzle-adapter": "1.6.
|
|
494
|
-
"@better-auth/kysely-adapter": "1.6.
|
|
495
|
-
"@better-auth/memory-adapter": "1.6.
|
|
496
|
-
"@better-auth/mongo-adapter": "1.6.
|
|
497
|
-
"@better-auth/prisma-adapter": "1.6.
|
|
498
|
-
"@better-auth/telemetry": "1.6.
|
|
492
|
+
"@better-auth/core": "1.6.32",
|
|
493
|
+
"@better-auth/drizzle-adapter": "1.6.32",
|
|
494
|
+
"@better-auth/kysely-adapter": "1.6.32",
|
|
495
|
+
"@better-auth/memory-adapter": "1.6.32",
|
|
496
|
+
"@better-auth/mongo-adapter": "1.6.32",
|
|
497
|
+
"@better-auth/prisma-adapter": "1.6.32",
|
|
498
|
+
"@better-auth/telemetry": "1.6.32"
|
|
499
499
|
},
|
|
500
500
|
"devDependencies": {
|
|
501
501
|
"@lynx-js/react": "^0.116.3",
|