Better auth creates repeated multiple cached calls with different keys using drizzle + configured cache #2278

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

Originally created by @eloi24 on GitHub (Nov 9, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Configure better-auth with drizzleAddapter and the drizzle instance should have also the cache object configured

Current vs. Expected behavior

Better auth creates two identical entries via drizzle cache, also when this entries are modified via update to the database they aren't invalidated

What version of Better Auth are you using?

1.3.34

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Pro",
    "release": "10.0.26200",
    "cpuCount": 12,
    "cpuModel": "AMD Ryzen 5 2600X Six-Core Processor           ",
    "totalMemory": "15.93 GB",
    "freeMemory": "5.37 GB"
  },
  "node": {
    "version": "v22.16.0",
    "env": "development"
  },
  "packageManager": {
    "name": "bun",
    "version": "1.3.1"
  },
  "frameworks": null,
  "databases": [
    {
      "name": "drizzle",
      "version": "0.44.7"
    }
  ],
  "betterAuth": {
    "version": "1.3.34",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

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

Additional context

No response

Originally created by @eloi24 on GitHub (Nov 9, 2025). ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce Configure better-auth with drizzleAddapter and the drizzle instance should have also the cache object configured ### Current vs. Expected behavior Better auth creates two identical entries via drizzle cache, also when this entries are modified via update to the database they aren't invalidated ### What version of Better Auth are you using? 1.3.34 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Pro", "release": "10.0.26200", "cpuCount": 12, "cpuModel": "AMD Ryzen 5 2600X Six-Core Processor ", "totalMemory": "15.93 GB", "freeMemory": "5.37 GB" }, "node": { "version": "v22.16.0", "env": "development" }, "packageManager": { "name": "bun", "version": "1.3.1" }, "frameworks": null, "databases": [ { "name": "drizzle", "version": "0.44.7" } ], "betterAuth": { "version": "1.3.34", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
Author
Owner

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

(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 9, 2025): (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

@dosubot[bot] commented on GitHub (Nov 9, 2025):

Yes, this is suited for GitHub. The issue you described—Better Auth creating repeated cached calls with different keys and failing to invalidate cache entries when using Drizzle with a configured cache—is a known bug in Better Auth versions 1.3.29 to 1.3.34. This bug is not fixed in 1.3.34 and is only resolved in build 5311 and later versions, which may be available as beta or nightly builds but are not yet released as stable npm versions. You can read more about the bug and the fix in this thread.

For now, the recommended solution is to upgrade to build 5311 or higher once it is available. If you can't upgrade immediately, you can work around the issue by performing filtering or cache management on the client side after fetching data with simpler queries. Cache/session invalidation issues have been reported in other contexts and were addressed in later versions, so this is a recognized area of improvement in Better Auth.

If you use custom endpoints to update user info, using Better Auth's built-in updateUser method or calling getSession with disableCookieCache: true can force a refresh of cached session data, but this does not address the underlying Drizzle cache key duplication bug.

Let me know if you want more technical details or upgrade instructions.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Nov 9, 2025): <!-- Answer --> Yes, this is suited for GitHub. The issue you described—Better Auth creating repeated cached calls with different keys and failing to invalidate cache entries when using Drizzle with a configured cache—is a known bug in Better Auth versions 1.3.29 to 1.3.34. This bug is not fixed in 1.3.34 and is only resolved in build 5311 and later versions, which may be available as beta or nightly builds but are not yet released as stable npm versions. You can read more about the bug and the fix in [this thread](https://github.com/better-auth/better-auth/issues/5767). For now, the recommended solution is to upgrade to build 5311 or higher once it is available. If you can't upgrade immediately, you can work around the issue by performing filtering or cache management on the client side after fetching data with simpler queries. Cache/session invalidation issues have been reported in other contexts and were addressed in later versions, so this is a recognized area of improvement in Better Auth. If you use custom endpoints to update user info, using Better Auth's built-in `updateUser` method or calling `getSession` with `disableCookieCache: true` can force a refresh of cached session data, but this does not address the underlying Drizzle cache key duplication bug. Let me know if you want more technical details or upgrade instructions. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/2b026e02-db57-413a-b451-b1c060561f0b?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/2b026e02-db57-413a-b451-b1c060561f0b?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/2b026e02-db57-413a-b451-b1c060561f0b?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/2b026e02-db57-413a-b451-b1c060561f0b?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2b026e02-db57-413a-b451-b1c060561f0b?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/2b026e02-db57-413a-b451-b1c060561f0b?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2b026e02-db57-413a-b451-b1c060561f0b?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/5870)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2278