[PR #8645] [CLOSED] fix: set stateless cookieCache maxAge to match session expiresIn #25015

Closed
opened 2026-04-15 22:41:29 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8645
Author: @himself65
Created: 3/16/2026
Status: Closed

Base: canaryHead: fix/stateless-maxage-default-8638


📝 Commits (1)

  • a5346db fix: set stateless cookieCache maxAge to match session expiresIn (#8638)

📊 Changes

1 file changed (+2 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/context/create-context.ts (+2 -0)

📄 Description

Summary

  • When no database is provided, Better Auth auto-configures stateless mode with cookieCache enabled and refreshCache: true. However, maxAge was not being set, so it defaulted to 5 minutes (60 * 5). This caused users in stateless mode to get logged out after 5 minutes instead of the documented 7 days.
  • Now maxAge defaults to session.expiresIn (7 days by default), matching the documented behavior.

Fixes #8638

Test plan

  • Verify that in stateless mode (no database), the cookieCache.maxAge defaults to 7 days (604800 seconds)
  • Verify that if session.expiresIn is explicitly set, maxAge uses that value instead
  • Verify that stateful mode (with database) is unaffected by this change

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/8645 **Author:** [@himself65](https://github.com/himself65) **Created:** 3/16/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/stateless-maxage-default-8638` --- ### 📝 Commits (1) - [`a5346db`](https://github.com/better-auth/better-auth/commit/a5346dbf8dd255e91d6880713208bc285eb6ea91) fix: set stateless cookieCache maxAge to match session expiresIn (#8638) ### 📊 Changes **1 file changed** (+2 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/context/create-context.ts` (+2 -0) </details> ### 📄 Description ## Summary - When no database is provided, Better Auth auto-configures stateless mode with `cookieCache` enabled and `refreshCache: true`. However, `maxAge` was not being set, so it defaulted to 5 minutes (`60 * 5`). This caused users in stateless mode to get logged out after 5 minutes instead of the documented 7 days. - Now `maxAge` defaults to `session.expiresIn` (7 days by default), matching the documented behavior. Fixes #8638 ## Test plan - [ ] Verify that in stateless mode (no database), the `cookieCache.maxAge` defaults to 7 days (604800 seconds) - [ ] Verify that if `session.expiresIn` is explicitly set, `maxAge` uses that value instead - [ ] Verify that stateful mode (with database) is unaffected by this change --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 22:41:29 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25015