Session Expiration Limited to 1 Day Despite 7-Day Configuration
We're experiencing a session expiration issue with Better Auth where our sessions are only valid for 1 day instead of 7, despite the specified configuration.
In our logs, we can see session creation with:
Relevant Configuration:
API Routes:
Client:
Issue Details:
better-auth: 1.2.7,
better-fetch: 1.1.2,
next": 15.2.4,
Any insights appreciated!
In our logs, we can see session creation with:
Relevant Configuration:
API Routes:
Client:
Issue Details:
- When checking
expiresAtin the database, session expiration is consistently set to createdAt + 1 day, not 7 days.
2. Our session cookie is set correctly but expires after ~5 min and is not renewed. - This causes authentication errors in our app when fetching from protected endpoints.
better-auth: 1.2.7,
better-fetch: 1.1.2,
next": 15.2.4,
Any insights appreciated!
Solution
I discovered that setting
The current documentation only states:
However, our investigation shows that
I suggest updating the documentation to clarify that:
Thank you for the great Library
rememberMe: true resolved our session expiration issue. Sessions were only lasting 1 day instead of the configured 7 days.The current documentation only states:
"rememberMe: If false, the user will be signed out when the browser is closed. (optional) (default: true)"
However, our investigation shows that
rememberMe has a more significant impact than documented. When rememberMe is false (or not explicitly set to true when signing in), it appears to override the session.expiresIn configuration, limiting session expiration to approximately creationTime + 1 day regardless of the configured 7-day expiration.I suggest updating the documentation to clarify that:
- The
rememberMeparameter affects not just browser-close behavior but also the maximum session duration - When
rememberMeis false, the session expiration is limited regardless of thesession.expiresInsetting - To achieve longer sessions as specified in
expiresIn, clients must explicitly passrememberMe: trueduring authentication
Thank you for the great Library