API Key Metadata is null?
For this configuration with v1.2.3:
I am trying a simple create:
But when I use the key, it's registered as valid, but with metadata set to the string
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
usePlural: true,
}),
emailAndPassword: {
enabled: true,
},
plugins: [
apiKey({
enableMetadata: true,
}),
organization(),
],
});export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
usePlural: true,
}),
emailAndPassword: {
enabled: true,
},
plugins: [
apiKey({
enableMetadata: true,
}),
organization(),
],
});I am trying a simple create:
const key = await auth.api.createApiKey({
body: {
name: body.name,
metadata: {
org: "org",
},
},
fetchOptions: {
headers: {
"Content-Type": "application/json",
},
},
headers: c.req.raw.headers,
});const key = await auth.api.createApiKey({
body: {
name: body.name,
metadata: {
org: "org",
},
},
fetchOptions: {
headers: {
"Content-Type": "application/json",
},
},
headers: c.req.raw.headers,
});But when I use the key, it's registered as valid, but with metadata set to the string
'null''null': (Verified this is the case on the DB side as well). const apiKey = c.req.header("x-api-key");
logger.error(`Received API key: ${apiKey}`);
if (!apiKey) {
return c.json(
{ error: "Unauthorized", details: "No API key provided" },
401,
);
}
const keyValid = await auth.api.verifyApiKey({
body: {
key: apiKey,
},
});
if (keyValid.error) {
return c.json({ error: "Unauthorized", details: "Invalid API key" }, 401);
}
const key = await auth.api.getApiKey({
headers: c.req.raw.headers,
query: {
id: keyValid.key?.id ?? "",
},
}); const apiKey = c.req.header("x-api-key");
logger.error(`Received API key: ${apiKey}`);
if (!apiKey) {
return c.json(
{ error: "Unauthorized", details: "No API key provided" },
401,
);
}
const keyValid = await auth.api.verifyApiKey({
body: {
key: apiKey,
},
});
if (keyValid.error) {
return c.json({ error: "Unauthorized", details: "Invalid API key" }, 401);
}
const key = await auth.api.getApiKey({
headers: c.req.raw.headers,
query: {
id: keyValid.key?.id ?? "",
},
});