@better-auth/api-key 1.6.14 → 1.6.16
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,4 +1,4 @@
|
|
|
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-Bubvdajw.mjs";
|
|
2
2
|
import { createAuthEndpoint, createAuthMiddleware } from "@better-auth/core/api";
|
|
3
3
|
import { base64Url } from "@better-auth/utils/base64";
|
|
4
4
|
import { createHash } from "@better-auth/utils/hash";
|
|
@@ -720,7 +720,7 @@ function createApiKey({ defaultKeyGenerator, configurations, schema, deleteAllEx
|
|
|
720
720
|
const { configId, name, expiresIn, prefix, remaining, metadata, refillAmount, refillInterval, permissions, rateLimitMax, rateLimitTimeWindow, rateLimitEnabled } = ctx.body;
|
|
721
721
|
const opts = resolveConfiguration(ctx.context, configurations, configId);
|
|
722
722
|
const keyGenerator = opts.customKeyGenerator || defaultKeyGenerator;
|
|
723
|
-
const session = await getSessionFromCtx(ctx);
|
|
723
|
+
const session = await getSessionFromCtx(ctx, { disableCookieCache: true });
|
|
724
724
|
const isClientRequest = ctx.request || ctx.headers;
|
|
725
725
|
if (isClientRequest && (refillAmount !== void 0 || refillInterval !== void 0 || rateLimitMax !== void 0 || rateLimitTimeWindow !== void 0 || rateLimitEnabled !== void 0 || permissions !== void 0 || remaining !== null)) throw APIError$1.from("BAD_REQUEST", API_KEY_ERROR_CODES.SERVER_ONLY_PROPERTY);
|
|
726
726
|
if (ctx.request && ctx.body.userId !== void 0) throw APIError$1.from("UNAUTHORIZED", API_KEY_ERROR_CODES.UNAUTHORIZED_SESSION);
|
|
@@ -1633,7 +1633,8 @@ function isRateLimited(apiKey, opts) {
|
|
|
1633
1633
|
//#endregion
|
|
1634
1634
|
//#region src/routes/verify-api-key.ts
|
|
1635
1635
|
async function validateApiKey({ key, ctx, lookupOpts, configurations, schema, permissions, expectedConfigId, runCustomValidator }) {
|
|
1636
|
-
const
|
|
1636
|
+
const hashedKey = lookupOpts.disableKeyHashing ? key : await defaultKeyHasher(key);
|
|
1637
|
+
const apiKey = await getApiKey$1(ctx, hashedKey, lookupOpts);
|
|
1637
1638
|
if (!apiKey) throw APIError$1.from("UNAUTHORIZED", API_KEY_ERROR_CODES.INVALID_API_KEY);
|
|
1638
1639
|
if (expectedConfigId !== void 0 && !configIdMatches(apiKey.configId, expectedConfigId)) throw APIError$1.from("UNAUTHORIZED", API_KEY_ERROR_CODES.INVALID_API_KEY);
|
|
1639
1640
|
const opts = resolveConfiguration(ctx.context, configurations, apiKey.configId);
|
|
@@ -1724,13 +1725,16 @@ async function validateApiKey({ key, ctx, lookupOpts, configurations, schema, pe
|
|
|
1724
1725
|
code: "RATE_LIMITED",
|
|
1725
1726
|
details: { tryAgainIn }
|
|
1726
1727
|
});
|
|
1727
|
-
const
|
|
1728
|
-
...apiKey,
|
|
1728
|
+
const mutations = {
|
|
1729
1729
|
...update,
|
|
1730
1730
|
remaining,
|
|
1731
1731
|
lastRefillAt,
|
|
1732
1732
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1733
1733
|
};
|
|
1734
|
+
const updated = {
|
|
1735
|
+
...apiKey,
|
|
1736
|
+
...mutations
|
|
1737
|
+
};
|
|
1734
1738
|
const performUpdate = async () => {
|
|
1735
1739
|
if (opts.storage === "database") return ctx.context.adapter.update({
|
|
1736
1740
|
model: API_KEY_TABLE_NAME,
|
|
@@ -1738,10 +1742,7 @@ async function validateApiKey({ key, ctx, lookupOpts, configurations, schema, pe
|
|
|
1738
1742
|
field: "id",
|
|
1739
1743
|
value: apiKey.id
|
|
1740
1744
|
}],
|
|
1741
|
-
update:
|
|
1742
|
-
...updated,
|
|
1743
|
-
id: void 0
|
|
1744
|
-
}
|
|
1745
|
+
update: mutations
|
|
1745
1746
|
});
|
|
1746
1747
|
else if (opts.storage === "secondary-storage" && opts.fallbackToDatabase) {
|
|
1747
1748
|
const dbUpdated = await ctx.context.adapter.update({
|
|
@@ -1750,16 +1751,19 @@ async function validateApiKey({ key, ctx, lookupOpts, configurations, schema, pe
|
|
|
1750
1751
|
field: "id",
|
|
1751
1752
|
value: apiKey.id
|
|
1752
1753
|
}],
|
|
1753
|
-
update:
|
|
1754
|
-
...updated,
|
|
1755
|
-
id: void 0
|
|
1756
|
-
}
|
|
1754
|
+
update: mutations
|
|
1757
1755
|
});
|
|
1758
1756
|
if (dbUpdated) await setApiKey(ctx, dbUpdated, opts);
|
|
1759
1757
|
return dbUpdated;
|
|
1760
1758
|
} else {
|
|
1761
|
-
await
|
|
1762
|
-
return
|
|
1759
|
+
const fresh = await getApiKey$1(ctx, hashedKey, opts);
|
|
1760
|
+
if (!fresh) return null;
|
|
1761
|
+
const merged = {
|
|
1762
|
+
...fresh,
|
|
1763
|
+
...mutations
|
|
1764
|
+
};
|
|
1765
|
+
await setApiKey(ctx, merged, opts);
|
|
1766
|
+
return merged;
|
|
1763
1767
|
}
|
|
1764
1768
|
};
|
|
1765
1769
|
let newApiKey = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/api-key",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.16",
|
|
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.6.
|
|
65
|
-
"better-auth": "1.6.
|
|
64
|
+
"@better-auth/core": "1.6.16",
|
|
65
|
+
"better-auth": "1.6.16"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@better-auth/utils": "0.4.1",
|
|
69
|
-
"better-call": "1.3.
|
|
70
|
-
"@better-auth/core": "^1.6.
|
|
71
|
-
"better-auth": "^1.6.
|
|
69
|
+
"better-call": "1.3.6",
|
|
70
|
+
"@better-auth/core": "^1.6.16",
|
|
71
|
+
"better-auth": "^1.6.16"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "tsdown",
|