[GH-ISSUE #8828] Better-Auth setting _better-auth-cookie-store cookie with invalid date #19835

Closed
opened 2026-04-15 19:11:21 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @ofek-frame on GitHub (Mar 29, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8828

Originally assigned to: @ping-maxwell on GitHub.

I'm using a nextjs app and the following header is being sent when I log in to my application:
Image

It seems to be related to a recent change:
03d2df6603/packages/better-auth/src/integrations/next-js.ts (L51)

But as I'm using Better auth 1.5.5, it seems like the Leaks unnecessary cookie commit did not fix this.

(Sorry for not matching the format, github removes it when you reference code)

Originally created by @ofek-frame on GitHub (Mar 29, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8828 Originally assigned to: @ping-maxwell on GitHub. I'm using a nextjs app and the following header is being sent when I log in to my application: <img width="739" height="23" alt="Image" src="https://github.com/user-attachments/assets/598cc1eb-2fae-4562-8cb8-c345bb8f0783" /> It seems to be related to a recent change: https://github.com/better-auth/better-auth/blob/03d2df66030ba7c020024d3fb4147a5cf9650192/packages/better-auth/src/integrations/next-js.ts#L51 But as I'm using Better auth 1.5.5, it seems like the `Leaks unnecessary cookie` commit did not fix this. (Sorry for not matching the format, github removes it when you reference code)
GiteaMirror added the platformbug labels 2026-04-15 19:11:21 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 29, 2026):

This is a known issue. The __better-auth-cookie-store cookie is a temporary test cookie used to detect if code is running in a Next.js Server Component vs Server Action/Route Handler [1].

The "leaks unnecessary cookie" fix from PR #8193 added a cookieStore.delete() call, but this didn't fully resolve the problem [2]. Next.js's cookieStore.delete() only sets the cookie value to empty without removing the key from its internal map, so an empty cookie still gets sent to clients .

There's an open PR #8799 with a proper fix that removes the delete call entirely and relies solely on maxAge: 0 for expiration .

Regarding the invalid date - Better Auth itself doesn't handle date serialization for cookies; it passes maxAge: 0 to either the better-call library or Next.js's cookies().set(), which then converts it to an Expires header [1]. The invalid date formatting is likely occurring in that conversion step.

Workaround until PR #8799 is merged: If you're experiencing issues with the nextCookies plugin, you could temporarily remove it or use query: { disableRefresh: true } for server-side calls .

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:4150387072 --> @dosubot[bot] commented on GitHub (Mar 29, 2026): <!-- Answer --> This is a known issue. The `__better-auth-cookie-store` cookie is a temporary test cookie used to detect if code is running in a Next.js Server Component vs Server Action/Route Handler [[1]](https://github.com/better-auth/better-auth/blob/03d2df66030ba7c020024d3fb4147a5cf9650192/packages/better-auth/src/integrations/next-js.ts). The "leaks unnecessary cookie" fix from [PR #8193](https://github.com/better-auth/better-auth/pull/8193) added a `cookieStore.delete()` call, but this **didn't fully resolve the problem** [[2]](https://github.com/better-auth/better-auth/issues/8784). Next.js's `cookieStore.delete()` only sets the cookie value to empty without removing the key from its internal map, so an empty cookie still gets sent to clients . There's an open [PR #8799](https://github.com/better-auth/better-auth/pull/8799) with a proper fix that removes the delete call entirely and relies solely on `maxAge: 0` for expiration . Regarding the invalid date - Better Auth itself doesn't handle date serialization for cookies; it passes `maxAge: 0` to either the better-call library or Next.js's `cookies().set()`, which then converts it to an `Expires` header [[1]](https://github.com/better-auth/better-auth/blob/03d2df66030ba7c020024d3fb4147a5cf9650192/packages/better-auth/src/integrations/next-js.ts). The invalid date formatting is likely occurring in that conversion step. **Workaround until PR #8799 is merged**: If you're experiencing issues with the `nextCookies` plugin, you could temporarily remove it or use `query: { disableRefresh: true }` for server-side calls . <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/0d451095-a6df-4e96-86df-363a81fdc4e7?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/0d451095-a6df-4e96-86df-363a81fdc4e7?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/0d451095-a6df-4e96-86df-363a81fdc4e7?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/0d451095-a6df-4e96-86df-363a81fdc4e7?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/0d451095-a6df-4e96-86df-363a81fdc4e7?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/0d451095-a6df-4e96-86df-363a81fdc4e7?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report) | [Other](https://app.dosu.dev/response-feedback/0d451095-a6df-4e96-86df-363a81fdc4e7?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20known%20issue.%20The%20%60__better-auth-cookie-store%60%20cookie%20is%20a%20temporary%20test%20cookie%20used%20to%20detect%20if%20code%20is%20running%20in%20a%20Next.js%20Server%20Component%20vs%20Server%20Action/Route%20Handler%20%5B%5B1%5D%5D%28https%3A//github.com/better-auth/better-auth/blob/03d2df66030ba7c020024d3fb4147a5cf9650192/packages/better-auth/src/integrations/next-js.ts%29.%0A%0AThe%20%22leaks%20unnecessary%20cookie%22%20fix%20from%20%5BPR%20%238193%5D%28https%3A//github.com/better-auth/better-auth/pull/8193%29%20added%20a%20%60cookieStore.delete%28%29%60%20call%2C%20but%20this%20%2A%2Adidn%27t%20fully%20resolve%20the%20problem%2A%2A%20%5B%5B2%5D%5D%28https%3A//github.com/better-auth/better-auth/issues/8784%29.%20Next.js%27s%20%60cookieStore.delete%28%29%60%20only%20sets%20the%20cookie%20value%20to%20empty%20without%20removing%20the%20key%20from%20its%20internal%20map%2C%20so%20an%20empty%20cookie%20still%20gets%20sent%20to%20clients%20.%0A%0AThere%27s%20an%20open%20%5BPR%20%238799%5D%28https%3A//github.com/better-auth/better-auth/pull/8799%29%20with%20a%20proper%20fix%20that%20removes%20the%20delete%20call%20entirely%20and%20relies%20solely%20on%20%60maxAge%3A%200%60%20for%20expiration%20.%0A%0ARegarding%20the%20invalid%20date%20-%20Better%20Auth%20itself%20doesn%27t%20handle%20date%20serialization%20for%20cookies%3B%20it%20passes%20%60maxAge%3A%200%60%20to%20either%20the%20better-call%20library%20or%20Next.js%27s%20%60cookies%28%29.set%28%29%60%2C%20which%20then%20converts%20it%20to%20an%20%60Expires%60%20header%20%5B%5B1%5D%5D%28https%3A//github.com/better-auth/better-auth/blob/03d2df66030ba7c020024d3fb4147a5cf9650192/packages/better-auth/src/integrations/next-js.ts%29.%20The%20invalid%20date%20formatting%20is%20likely%20occurring%20in%20that%20conversion%20step.%0A%0A%2A%2AWorkaround%20until%20PR%20%238799%20is%20merged%2A%2A%3A%20If%20you%27re%20experiencing%20issues%20with%20the%20%60nextCookies%60%20plugin%2C%20you%20could%20temporarily%20remove%20it%20or%20use%20%60query%3A%20%7B%20disableRefresh%3A%20true%20%7D%60%20for%20server-side%20calls%20.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&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/8828)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19835