[GH-ISSUE #4491] dontRememberMe does not work when cookie cache is enabled #18586

Closed
opened 2026-04-15 17:06:50 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @widavies on GitHub (Sep 6, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4491

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Enable cookie cache
  2. Sign in with rememberMe: false
Image

Current vs. Expected behavior

When rememberMe: false, closing the tab should sign the user out, but it does not.

What version of Better Auth are you using?

1.3.8

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Home",
    "release": "10.0.26100",
    "cpuCount": 32,
    "cpuModel": "AMD Ryzen 9 9950X 16-Core Processor            ",
    "totalMemory": "61.65 GB",
    "freeMemory": "26.73 GB"
  },
  "node": {
    "version": "v24.4.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.4.2"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "^15.5.2"
    },
    {
      "name": "react",
      "version": "^19.1.1"
    },
    {
      "name": "hono",
      "version": "^4.9.6"
    }
  ],
  "databases": null,
  "betterAuth": {
    "version": "0.1.0",
    "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
  },
  session: {
    cookieCache: {
      enabled: true,
      maxAge: 5 * 60, // Cache duration in seconds
    },
  },

});

Additional context

I believe this bug is caused because the cookie expiration for the session_data cookie is not set to Session

Image
Originally created by @widavies on GitHub (Sep 6, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4491 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Enable cookie cache 2. Sign in with `rememberMe: false` <img width="1360" height="202" alt="Image" src="https://github.com/user-attachments/assets/e62cee0f-4b5c-4e4d-b73a-20e1ee27ab3c" /> ### Current vs. Expected behavior When `rememberMe: false`, closing the tab should sign the user out, but it does not. ### What version of Better Auth are you using? 1.3.8 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Home", "release": "10.0.26100", "cpuCount": 32, "cpuModel": "AMD Ryzen 9 9950X 16-Core Processor ", "totalMemory": "61.65 GB", "freeMemory": "26.73 GB" }, "node": { "version": "v24.4.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.4.2" }, "frameworks": [ { "name": "next", "version": "^15.5.2" }, { "name": "react", "version": "^19.1.1" }, { "name": "hono", "version": "^4.9.6" } ], "databases": null, "betterAuth": { "version": "0.1.0", "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 }, session: { cookieCache: { enabled: true, maxAge: 5 * 60, // Cache duration in seconds }, }, }); ``` ### Additional context I believe this bug is caused because the cookie expiration for the `session_data` cookie is _not_ set to `Session` <img width="1360" height="202" alt="Image" src="https://github.com/user-attachments/assets/d0426659-f813-42f5-a841-79c085ac4809" />
GiteaMirror added the lockedbug labels 2026-04-15 17:06:51 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 6, 2025):

Hi @widavies! I'm Dosu and I’m helping the better-auth team.

This is a known limitation in Better Auth v1.3.8: when cookie cache is enabled, the session_data cookie always gets a fixed expiration based on the cache's maxAge, even if you set rememberMe: false. This means the cookie persists until its expiration date, so closing the tab won't sign the user out as you'd expect for a session cookie. The logic for cookie expiration prioritizes cookieCache over the rememberMe flag, so the expected "session-only" behavior is overridden by the cache setting details.

Currently, there isn't a built-in workaround to force session-only cookies when cookie cache is enabled. If you need true session cookie behavior, you'll need to disable cookie cache or adjust your session strategy accordingly.

To reply, just mention @dosu.


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

<!-- gh-comment-id:3263264526 --> @dosubot[bot] commented on GitHub (Sep 6, 2025): <!-- Greeting --> Hi @widavies! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known limitation in Better Auth v1.3.8: when cookie cache is enabled, the session_data cookie always gets a fixed expiration based on the cache's maxAge, even if you set `rememberMe: false`. This means the cookie persists until its expiration date, so closing the tab won't sign the user out as you'd expect for a session cookie. The logic for cookie expiration prioritizes cookieCache over the rememberMe flag, so the expected "session-only" behavior is overridden by the cache setting [details](https://github.com/better-auth/better-auth/pull/4299). Currently, there isn't a built-in workaround to force session-only cookies when cookie cache is enabled. If you need true session cookie behavior, you'll need to disable cookie cache or adjust your session strategy accordingly. <!-- 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/a77093ed-59b5-47dd-9f4c-b8f90da601c9?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/a77093ed-59b5-47dd-9f4c-b8f90da601c9?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/a77093ed-59b5-47dd-9f4c-b8f90da601c9?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/a77093ed-59b5-47dd-9f4c-b8f90da601c9?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/a77093ed-59b5-47dd-9f4c-b8f90da601c9?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/a77093ed-59b5-47dd-9f4c-b8f90da601c9?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/a77093ed-59b5-47dd-9f4c-b8f90da601c9?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/4491)
Author
Owner

@widavies commented on GitHub (Sep 6, 2025):

This does make sense, because when rememberMe: false the cookie cache is entirely pointless as only one of Expires and Max-Age can be set on the cookie. I guess the tradeoff is between 1) Remember me will not appear to work until the cookie cache max-age is hit, potentially a security implication or 2) the cookie cache is disabled in rememberMe: false mode.

Maybe the best answer is to make this configurable?

<!-- gh-comment-id:3263267610 --> @widavies commented on GitHub (Sep 6, 2025): This does make sense, because when `rememberMe: false` the cookie cache is entirely pointless as only one of `Expires` and `Max-Age` can be set on the cookie. I guess the tradeoff is between 1) `Remember me` will not appear to work until the cookie cache `max-age` is hit, potentially a security implication or 2) the cookie cache is disabled in `rememberMe: false` mode. Maybe the best answer is to make this configurable?
Author
Owner

@dosubot[bot] commented on GitHub (Sep 6, 2025):

You're right—currently, Better Auth always sets the session_data cookie's expiration based on the cookieCache config if enabled, regardless of the rememberMe flag. This means you can't get true session-only cookies when cookie cache is on, and there's no built-in way to make this conditional or configurable in the current version. The dontRememberMe flag only affects the session_token cookie, not session_data, so the cache persists until its maxAge even if the user doesn't want to be remembered (source).

To make this configurable, the core cookie logic (like getCookies and setCookieCache) would need to check the rememberMe flag or a new config option when setting the session_data cookie. Right now, the only workaround is to disable cookie cache when rememberMe is false, but this isn't automatic.

If configurability here is important for your use case (for example, to avoid security issues or UX confusion), it would require a code change to add a conditional or hook for this behavior. The code structure would allow for this with some targeted updates.

To reply, just mention @dosu.


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

<!-- gh-comment-id:3263268475 --> @dosubot[bot] commented on GitHub (Sep 6, 2025): <!-- Answer --> You're right—currently, Better Auth always sets the session_data cookie's expiration based on the cookieCache config if enabled, regardless of the rememberMe flag. This means you can't get true session-only cookies when cookie cache is on, and there's no built-in way to make this conditional or configurable in the current version. The dontRememberMe flag only affects the session_token cookie, not session_data, so the cache persists until its maxAge even if the user doesn't want to be remembered ([source](https://github.com/better-auth/better-auth/blob/a39d09d3ff83b526fb9caf691d3bbcb3b7b2335b/packages/better-auth/src/cookies/index.ts)). To make this configurable, the core cookie logic (like getCookies and setCookieCache) would need to check the rememberMe flag or a new config option when setting the session_data cookie. Right now, the only workaround is to disable cookie cache when rememberMe is false, but this isn't automatic. If configurability here is important for your use case (for example, to avoid security issues or UX confusion), it would require a code change to add a conditional or hook for this behavior. The code structure would allow for this with some targeted updates. <!-- 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/3a6c45e8-ad6f-45ad-a79a-c69a8a99233c?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/3a6c45e8-ad6f-45ad-a79a-c69a8a99233c?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/3a6c45e8-ad6f-45ad-a79a-c69a8a99233c?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/3a6c45e8-ad6f-45ad-a79a-c69a8a99233c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/3a6c45e8-ad6f-45ad-a79a-c69a8a99233c?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/3a6c45e8-ad6f-45ad-a79a-c69a8a99233c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/3a6c45e8-ad6f-45ad-a79a-c69a8a99233c?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/4491)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18586