Kysely CamelCasePlugin breaks join parsing in better-auth adapter #2655

Closed
opened 2026-03-13 10:11:12 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @coji on GitHub (Jan 5, 2026).

Is this suited for GitHub?

  • Yes, this is suited for github

To Reproduce

  1. Configure Kysely with CamelCasePlugin and use it in better-auth (Kysely adapter).
  2. Use SQLite/libsql and create a session + user (e.g., via anonymous plugin).
  3. Call auth.api.getSession() or ctx.internalAdapter.findSession(sessionToken).
  4. Observe that findSession returns null even though the session row exists and the token is valid.

Current vs. Expected behavior

Current: findSession returns null when CamelCasePlugin is enabled. The session exists in the DB and the signed cookie token is valid, but findSession fails.

Expected: findSession should return { session, user } regardless of CamelCasePlugin, or the adapter should handle camelCased join keys.

Better Auth version

1.4.10

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:34 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T8112",
    "release": "25.2.0",
    "cpuCount": 8,
    "cpuModel": "Apple M2",
    "totalMemory": "24.00 GB",
    "freeMemory": "0.34 GB"
  },
  "node": {
    "version": "v22.21.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.4"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "19.2.3"
    }
  ],
  "databases": [
    {
      "name": "@libsql/client",
      "version": "0.15.15"
    },
    {
      "name": "kysely",
      "version": "0.28.9"
    }
  ],
  "betterAuth": {
    "version": "1.4.10",
    "config": null
  }
}

Which area(s) are affected?

  • Backend
  • Package

Auth config

import { betterAuth } from "better-auth"
import { anonymous } from "better-auth/plugins"
import { Kysely, CamelCasePlugin } from "kysely"
import { LibsqlDialect } from "kysely-libsql"

const db = new Kysely({
  dialect: new LibsqlDialect({ url: "file:./data/local.db" }),
  plugins: [new CamelCasePlugin()],
})

export const auth = betterAuth({
  database: { db, type: "sqlite" },
  user: {
    modelName: "user",
    fields: {
      emailVerified: "email_verified",
      createdAt: "created_at",
      updatedAt: "updated_at",
      isAnonymous: "is_anonymous",
    },
  },
  session: {
    modelName: "session",
    fields: {
      expiresAt: "expires_at",
      createdAt: "created_at",
      updatedAt: "updated_at",
      ipAddress: "ip_address",
      userAgent: "user_agent",
      userId: "user_id",
    },
  },
  plugins: [anonymous()],
})

Additional context

The failure seems to come from join parsing. processJoinedResults expects keys like _joined_user_user_id, but CamelCasePlugin converts result keys (e.g. _joinedUserUserId), so the join fields are never recognized and user becomes null. Workaround: use a separate Kysely instance without CamelCasePlugin for better-auth.

Originally created by @coji on GitHub (Jan 5, 2026). ## Is this suited for GitHub? - [x] Yes, this is suited for github ## To Reproduce 1. Configure Kysely with CamelCasePlugin and use it in better-auth (Kysely adapter). 2. Use SQLite/libsql and create a session + user (e.g., via anonymous plugin). 3. Call auth.api.getSession() or ctx.internalAdapter.findSession(sessionToken). 4. Observe that findSession returns null even though the session row exists and the token is valid. ## Current vs. Expected behavior **Current:** findSession returns null when CamelCasePlugin is enabled. The session exists in the DB and the signed cookie token is valid, but findSession fails. **Expected:** findSession should return { session, user } regardless of CamelCasePlugin, or the adapter should handle camelCased join keys. ## Better Auth version 1.4.10 ## System info ```json { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:34 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T8112", "release": "25.2.0", "cpuCount": 8, "cpuModel": "Apple M2", "totalMemory": "24.00 GB", "freeMemory": "0.34 GB" }, "node": { "version": "v22.21.1", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.4" }, "frameworks": [ { "name": "react", "version": "19.2.3" } ], "databases": [ { "name": "@libsql/client", "version": "0.15.15" }, { "name": "kysely", "version": "0.28.9" } ], "betterAuth": { "version": "1.4.10", "config": null } } ``` ## Which area(s) are affected? - Backend - Package ## Auth config ```ts import { betterAuth } from "better-auth" import { anonymous } from "better-auth/plugins" import { Kysely, CamelCasePlugin } from "kysely" import { LibsqlDialect } from "kysely-libsql" const db = new Kysely({ dialect: new LibsqlDialect({ url: "file:./data/local.db" }), plugins: [new CamelCasePlugin()], }) export const auth = betterAuth({ database: { db, type: "sqlite" }, user: { modelName: "user", fields: { emailVerified: "email_verified", createdAt: "created_at", updatedAt: "updated_at", isAnonymous: "is_anonymous", }, }, session: { modelName: "session", fields: { expiresAt: "expires_at", createdAt: "created_at", updatedAt: "updated_at", ipAddress: "ip_address", userAgent: "user_agent", userId: "user_id", }, }, plugins: [anonymous()], }) ``` ## Additional context The failure seems to come from join parsing. processJoinedResults expects keys like _joined_user_user_id, but CamelCasePlugin converts result keys (e.g. _joinedUserUserId), so the join fields are never recognized and user becomes null. Workaround: use a separate Kysely instance without CamelCasePlugin for better-auth.
GiteaMirror added the bug label 2026-03-13 10:11:12 -05:00
Author
Owner

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

It looks like you are encountering an issue with using the CamelCasePlugin in Kysely when integrated with Better Auth, causing findSession to return null despite having a valid session. This is due to the join parsing failing as the keys are transformed by the CamelCasePlugin, resulting in unrecognized join fields.

A potential workaround is to set up a separate Kysely instance without the CamelCasePlugin specifically for Better Auth to ensure that the join fields are properly recognized.

If you need further assistance or have specific scenarios you'd like to discuss, feel free to tag @better-auth-agent for more direct help! What other features of Better Auth are you interested in exploring?

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 5, 2026): It looks like you are encountering an issue with using the CamelCasePlugin in Kysely when integrated with Better Auth, causing `findSession` to return null despite having a valid session. This is due to the join parsing failing as the keys are transformed by the CamelCasePlugin, resulting in unrecognized join fields. A potential workaround is to set up a separate Kysely instance without the CamelCasePlugin specifically for Better Auth to ensure that the join fields are properly recognized. If you need further assistance or have specific scenarios you'd like to discuss, feel free to tag @better-auth-agent for more direct help! What other features of Better Auth are you interested in exploring? _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/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2655