apiKey.list() TypeScript types don't match runtime response in v1.5.0-beta.10 #2790

Closed
opened 2026-03-13 10:20:25 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @turisanapo on GitHub (Jan 30, 2026).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Install better-auth@1.5.0-beta.10
  2. Create an auth client with the apiKey plugin:
import { createAuthClient } from "better-auth/client";
import { apiKeyClient } from "better-auth/client/plugins";

const authClient = createAuthClient({
  baseURL: "...",
  plugins: [apiKeyClient()],
});
  1. Call apiKey.list():
const { data, error } = await authClient.apiKey.list();
data.map((key) => key.id); // TypeError: data.map is not a function
  1. TypeScript shows data as an array type, but at runtime it's { apiKeys: [...] }

Current vs. Expected behavior

Expected: authClient.apiKey.list() returns data as an array that can be directly mapped:

const { data } = await authClient.apiKey.list();
data.map((key) => key.id); // works - data is ApiKey[]

Actual: data is returned as an object with an apiKeys property, causing TypeError: data.map is not a function:

const { data } = await authClient.apiKey.list();
// data is { apiKeys: ApiKey[] }, not ApiKey[]
data.apiKeys.map((key) => key.id); // workaround needed

What version of Better Auth are you using?

v1.5.0-beta.10

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:56 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T8132",
    "release": "25.1.0",
    "cpuCount": 10,
    "cpuModel": "Apple M4",
    "totalMemory": "16.00 GB",
    "freeMemory": "0.14 GB"
  },
  "node": {
    "version": "v24.9.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.0"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "Unknown",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @turisanapo on GitHub (Jan 30, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Install `better-auth@1.5.0-beta.10` 2. Create an auth client with the apiKey plugin: ```js import { createAuthClient } from "better-auth/client"; import { apiKeyClient } from "better-auth/client/plugins"; const authClient = createAuthClient({ baseURL: "...", plugins: [apiKeyClient()], }); ``` 3. Call `apiKey.list()`: ```js const { data, error } = await authClient.apiKey.list(); data.map((key) => key.id); // TypeError: data.map is not a function ``` 4. TypeScript shows `data` as an array type, but at runtime it's `{ apiKeys: [...] }` ### Current vs. Expected behavior **Expected:** `authClient.apiKey.list()` returns `data` as an array that can be directly mapped: ```js const { data } = await authClient.apiKey.list(); data.map((key) => key.id); // works - data is ApiKey[] ``` **Actual**: data is returned as an object with an apiKeys property, causing `TypeError: data.map is not a function`: ```js const { data } = await authClient.apiKey.list(); // data is { apiKeys: ApiKey[] }, not ApiKey[] data.apiKeys.map((key) => key.id); // workaround needed ``` ### What version of Better Auth are you using? v1.5.0-beta.10 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:56 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T8132", "release": "25.1.0", "cpuCount": 10, "cpuModel": "Apple M4", "totalMemory": "16.00 GB", "freeMemory": "0.14 GB" }, "node": { "version": "v24.9.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.0" }, "frameworks": null, "databases": null, "betterAuth": { "version": "Unknown", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 10:20:25 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 30, 2026):

It looks like you've encountered a discrepancy between the TypeScript types and the actual runtime response of authClient.apiKey.list() in version 1.5.0-beta.10. At runtime, the response you are seeing is an object structured as { apiKeys: [...] }, but TypeScript expects it to be an array directly.

This is a known issue where the TypeScript types are not aligning with the actual API responses. The issue arises due to the incorrect expectation in the TypeScript definitions regarding the shape of the response.

To work around this, you can access the keys using the apiKeys property like this:

const { data } = await authClient.apiKey.list();
data.apiKeys.map((key) => key.id); // works using apiKeys property

Currently, the TypeScript return types are expected to be fixed in a future release to better align with the API's behavior [1]. If you're looking for a more robust solution or if this issue persists, I suggest tagging Beka or Max (@bekacru or @ping__) for more assistance as they might have specific updates on this topic.

Is there something specific you'd like to achieve with apiKey.list(), or do you have any other questions about Better Auth?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Jan 30, 2026): It looks like you've encountered a discrepancy between the TypeScript types and the actual runtime response of `authClient.apiKey.list()` in version 1.5.0-beta.10. At runtime, the response you are seeing is an object structured as `{ apiKeys: [...] }`, but TypeScript expects it to be an array directly. This is a known issue where the TypeScript types are not aligning with the actual API responses. The issue arises due to the incorrect expectation in the TypeScript definitions regarding the shape of the response. To work around this, you can access the keys using the `apiKeys` property like this: ```js const { data } = await authClient.apiKey.list(); data.apiKeys.map((key) => key.id); // works using apiKeys property ``` Currently, the TypeScript return types are expected to be fixed in a future release to better align with the API's behavior [[1]](https://github.com/better-auth/better-auth/issues/1884). If you're looking for a more robust solution or if this issue persists, I suggest tagging Beka or Max (@bekacru or @ping__) for more assistance as they might have specific updates on this topic. Is there something specific you'd like to achieve with `apiKey.list()`, or do you have any other questions about Better Auth? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@bytaesu commented on GitHub (Jan 31, 2026):

Hi @turisanapo, I'm looking into this

@bytaesu commented on GitHub (Jan 31, 2026): Hi @turisanapo, I'm looking into this
Author
Owner

@bytaesu commented on GitHub (Jan 31, 2026):

Hi @turisanapo,

There was an intentional breaking change introduced in https://github.com/better-auth/better-auth/pull/7424 to support pagination.

It is applied in v1.5-beta, and data.apiKeys.map() is now the new usage 🙂

@bytaesu commented on GitHub (Jan 31, 2026): Hi @turisanapo, There was an intentional breaking change introduced in https://github.com/better-auth/better-auth/pull/7424 to support pagination. It is applied in `v1.5-beta`, and `data.apiKeys.map()` is now the new usage 🙂
Author
Owner

@turisanapo commented on GitHub (Jan 31, 2026):

@bytaesu Thanks for the clarification! After restarting my TypeScript server, the types are now correct. The issue was on my end. Apologies for the noise. Feel free to close this.

@turisanapo commented on GitHub (Jan 31, 2026): @bytaesu Thanks for the clarification! After restarting my TypeScript server, the types are now correct. The issue was on my end. Apologies for the noise. Feel free to close this.
Author
Owner

@bytaesu commented on GitHub (Jan 31, 2026):

No worries @turisanapo, glad to hear the issue has been resolved 😄

@bytaesu commented on GitHub (Jan 31, 2026): No worries @turisanapo, glad to hear the issue has been resolved 😄
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2790