@better-auth/api-key 1.7.0-beta.8 → 1.7.0-rc.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/dist/client.mjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { n as API_KEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-
|
|
1
|
+
import { n as API_KEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-DvOZbzQP.mjs";
|
|
2
2
|
import { createAuthEndpoint, createAuthMiddleware } from "@better-auth/core/api";
|
|
3
|
+
import { getIP } from "@better-auth/core/utils/ip";
|
|
3
4
|
import { base64Url } from "@better-auth/utils/base64";
|
|
4
5
|
import { createHash } from "@better-auth/utils/hash";
|
|
5
6
|
import { BetterAuthError } from "better-auth";
|
|
@@ -11,8 +12,6 @@ import { generateId } from "@better-auth/core/utils/id";
|
|
|
11
12
|
import { safeJSONParse } from "@better-auth/core/utils/json";
|
|
12
13
|
import * as z from "zod";
|
|
13
14
|
import { mapConcurrent } from "@better-auth/core/utils/async";
|
|
14
|
-
import { isDevelopment, isTest } from "@better-auth/core/env";
|
|
15
|
-
import { isValidIP, normalizeIP } from "@better-auth/core/utils/ip";
|
|
16
15
|
import { role } from "better-auth/plugins/access";
|
|
17
16
|
import { parseJSON } from "better-auth/client";
|
|
18
17
|
//#region src/adapter.ts
|
|
@@ -576,21 +575,6 @@ const getDate = (span, unit = "ms") => {
|
|
|
576
575
|
function isAPIError(error) {
|
|
577
576
|
return error instanceof APIError || error instanceof APIError$1 || error?.name === "APIError";
|
|
578
577
|
}
|
|
579
|
-
const LOCALHOST_IP = "127.0.0.1";
|
|
580
|
-
function getIp(req, options) {
|
|
581
|
-
if (options.advanced?.ipAddress?.disableIpTracking) return null;
|
|
582
|
-
const headers = "headers" in req ? req.headers : req;
|
|
583
|
-
const ipHeaders = options.advanced?.ipAddress?.ipAddressHeaders || ["x-forwarded-for"];
|
|
584
|
-
for (const key of ipHeaders) {
|
|
585
|
-
const value = "get" in headers ? headers.get(key) : headers[key];
|
|
586
|
-
if (typeof value === "string") {
|
|
587
|
-
const ip = value.split(",")[0].trim();
|
|
588
|
-
if (isValidIP(ip)) return normalizeIP(ip, { ipv6Subnet: options.advanced?.ipAddress?.ipv6Subnet });
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
if (isTest() || isDevelopment()) return LOCALHOST_IP;
|
|
592
|
-
return null;
|
|
593
|
-
}
|
|
594
578
|
//#endregion
|
|
595
579
|
//#region src/routes/create-api-key.ts
|
|
596
580
|
const createApiKeyBodySchema = z.object({
|
|
@@ -2381,7 +2365,7 @@ function apiKey(_configurations, _options) {
|
|
|
2381
2365
|
token: key,
|
|
2382
2366
|
userId: apiKey.referenceId,
|
|
2383
2367
|
userAgent: ctx.request?.headers.get("user-agent") ?? null,
|
|
2384
|
-
ipAddress: ctx.request ?
|
|
2368
|
+
ipAddress: ctx.request ? getIP(ctx.request, ctx.context.options) : null,
|
|
2385
2369
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2386
2370
|
updatedAt: /* @__PURE__ */ new Date(),
|
|
2387
2371
|
expiresAt: apiKey.expiresAt || getDate(ctx.context.options.session?.expiresIn || 3600 * 24 * 7, "ms")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/api-key",
|
|
3
|
-
"version": "1.7.0-
|
|
3
|
+
"version": "1.7.0-rc.0",
|
|
4
4
|
"description": "API Key plugin for Better Auth.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,14 +61,14 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"tsdown": "0.21.1",
|
|
64
|
-
"@better-auth/core": "1.7.0-
|
|
65
|
-
"better-auth": "1.7.0-
|
|
64
|
+
"@better-auth/core": "1.7.0-rc.0",
|
|
65
|
+
"better-auth": "1.7.0-rc.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@better-auth/utils": "0.4.2",
|
|
69
|
-
"better-call": "1.3.
|
|
70
|
-
"@better-auth/core": "^1.7.0-
|
|
71
|
-
"better-auth": "^1.7.0-
|
|
69
|
+
"better-call": "1.3.7",
|
|
70
|
+
"@better-auth/core": "^1.7.0-rc.0",
|
|
71
|
+
"better-auth": "^1.7.0-rc.0"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "tsdown",
|