Additional fields with type: 'string[]' are inferred as number[] #2262

Closed
opened 2026-03-13 09:39:28 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @alexw-at on GitHub (Nov 5, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create auth with additionalFields config that uses type: 'string[]' (see auth config)
  2. Use authClient.useSession()
  3. Additional field has type number[]
const { data } = authClient.useSession();

// Argument of type 'string' is not assignable to parameter of type 'number'
const isAdmin = data?.user.roles.includes('admin');

Current vs. Expected behavior

Additional fields with type: 'string[]' should be type string[] and not number[]

What version of Better Auth are you using?

1.4.0-beta.15

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Enterprise",
    "release": "10.0.26100",
    "cpuCount": 8,
    "cpuModel": "11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz",
    "totalMemory": "31.69 GB",
    "freeMemory": "14.52 GB"
  },
  "node": {
    "version": "v22.20.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.3"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "^19.0.0"
    }
  ],
  "databases": null,
  "betterAuth": {
    "version": "^1.4.0-beta.15",
    "config": {
      "session": {
        "expiresIn": 604800,
        "cookieCache": {
          "enabled": true,
          "maxAge": 2592000,
          "strategy": "jwe",
          "refreshCache": true
        }
      },
      "user": {
        "additionalFields": {
          "roles": {
            "type": "string[]",
            "input": false
          }
        }
      },
      "plugins": [
        {
          "name": "generic-oauth",
          "config": {
            "id": "generic-oauth",
            "endpoints": {},
            "$ERROR_CODES": {
              "INVALID_OAUTH_CONFIGURATION": "Invalid OAuth configuration"
            }
          }
        }
      ]
    }
  }
}

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

Client, Types

Auth config (if applicable)

export const auth = betterAuth({
  // ...
  user: {
    additionalFields: {
      roles: {
        type: 'string[]',
        input: false,
      },
    },
  },
  plugins: [
    genericOAuth({
      config: [
        {
          // ...
          mapProfileToUser: profile => ({
            name: profile.name,
            roles: profile.roles,
          }),
        },
      ],
    }),
  ],
});


export const authClient = createAuthClient({
  baseURL: 'http://localhost:3000',
  plugins: [inferAdditionalFields<typeof auth>(), genericOAuthClient()],
});

Additional context

No response

Originally created by @alexw-at on GitHub (Nov 5, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create auth with `additionalFields` config that uses `type: 'string[]'` (see auth config) 2. Use `authClient.useSession()` 3. Additional field has type `number[]` ```ts const { data } = authClient.useSession(); // Argument of type 'string' is not assignable to parameter of type 'number' const isAdmin = data?.user.roles.includes('admin'); ``` ### Current vs. Expected behavior Additional fields with `type: 'string[]'` should be type `string[]` and not `number[]` ### What version of Better Auth are you using? 1.4.0-beta.15 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Enterprise", "release": "10.0.26100", "cpuCount": 8, "cpuModel": "11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz", "totalMemory": "31.69 GB", "freeMemory": "14.52 GB" }, "node": { "version": "v22.20.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.3" }, "frameworks": [ { "name": "react", "version": "^19.0.0" } ], "databases": null, "betterAuth": { "version": "^1.4.0-beta.15", "config": { "session": { "expiresIn": 604800, "cookieCache": { "enabled": true, "maxAge": 2592000, "strategy": "jwe", "refreshCache": true } }, "user": { "additionalFields": { "roles": { "type": "string[]", "input": false } } }, "plugins": [ { "name": "generic-oauth", "config": { "id": "generic-oauth", "endpoints": {}, "$ERROR_CODES": { "INVALID_OAUTH_CONFIGURATION": "Invalid OAuth configuration" } } } ] } } } ``` ### Which area(s) are affected? (Select all that apply) Client, Types ### Auth config (if applicable) ```typescript export const auth = betterAuth({ // ... user: { additionalFields: { roles: { type: 'string[]', input: false, }, }, }, plugins: [ genericOAuth({ config: [ { // ... mapProfileToUser: profile => ({ name: profile.name, roles: profile.roles, }), }, ], }), ], }); export const authClient = createAuthClient({ baseURL: 'http://localhost:3000', plugins: [inferAdditionalFields<typeof auth>(), genericOAuthClient()], }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 09:39:28 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 5, 2025):

Hi there! Thanks for opening this issue. It looks like the additional field “roles” defined as type 'string[]' is incorrectly inferred as number[] in the authClient session data. This is a type inference issue we’re aware of in version 1.4.0-beta.15, and our team is investigating a permanent fix. As a workaround, you can explicitly cast or annotate the field as string[] on the client side when using authClient.useSession(). For example, you might extract the roles and cast them, or manually define an interface for your user type, ensuring that roles is correctly typed as string[] [1].

Have you tried this approach, or would you like more detailed guidance on how to implement the workaround? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 5, 2025): Hi there! Thanks for opening this issue. It looks like the additional field “roles” defined as type 'string[]' is incorrectly inferred as number[] in the authClient session data. This is a type inference issue we’re aware of in version 1.4.0-beta.15, and our team is investigating a permanent fix. As a workaround, you can explicitly cast or annotate the field as string[] on the client side when using authClient.useSession(). For example, you might extract the roles and cast them, or manually define an interface for your user type, ensuring that roles is correctly typed as string[] [[1]](https://github.com/better-auth/better-auth/issues/4125). Have you tried this approach, or would you like more detailed guidance on how to implement the workaround? Tag @better-auth-agent if you would like an answer from the Agent. <!-- 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

@VishalDevx commented on GitHub (Nov 5, 2025):

Hi! I'd like to work on this issue. I can see the type inference for string[] additionalFields is incorrectly resolving to number[]. I'll investigate the inferAdditionalFields plugin and type definitions. Is this still available?

@VishalDevx commented on GitHub (Nov 5, 2025): Hi! I'd like to work on this issue. I can see the type inference for string[] additionalFields is incorrectly resolving to number[]. I'll investigate the inferAdditionalFields plugin and type definitions. Is this still available?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2262