mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-28 09:56:25 -05:00
fix(api-key): creating API keys metadata always returns null (#1698)
This commit is contained in:
@@ -489,6 +489,18 @@ describe("api-key", async () => {
|
||||
|
||||
expect(apiKey).not.toBeNull();
|
||||
expect(apiKey.metadata).toEqual(metadata);
|
||||
|
||||
const res = await auth.api.getApiKey({
|
||||
query: {
|
||||
id: apiKey.id,
|
||||
},
|
||||
headers,
|
||||
});
|
||||
|
||||
expect(res).not.toBeNull();
|
||||
if (res) {
|
||||
expect(res.metadata).toEqual(metadata);
|
||||
}
|
||||
});
|
||||
|
||||
it("create API key's returned metadata should be an object", async () => {
|
||||
|
||||
@@ -275,14 +275,8 @@ export function createApiKey({
|
||||
};
|
||||
|
||||
if (metadata) {
|
||||
const parseMetadata = parseInputData(
|
||||
data,
|
||||
apiKeySchema({
|
||||
rateLimitMax: opts.rateLimit.maxRequests!,
|
||||
timeWindow: opts.rateLimit.timeWindow!,
|
||||
}).apikey,
|
||||
);
|
||||
data.metadata = parseMetadata.metadata ?? null;
|
||||
//@ts-expect-error - we intentionally save the metadata as string on DB.
|
||||
data.metadata = schema.apikey.fields.metadata.transform.input(metadata);
|
||||
}
|
||||
|
||||
const apiKey = await ctx.context.adapter.create<ApiKey>({
|
||||
|
||||
Reference in New Issue
Block a user