New sessions keep expiring after only 1 day, despite config being set to 7 days

Hi, I created a Next.js project with better-auth recently, but I keep running into a problem: every time I create a new session by signing-in, the session expires after only 1 day. I'm not sure why this is happening, it happens even if I specify 7 days for the expiresIn property under session. Attached is a screenshot of what the session looks like in my database and below is my config file. Does anyone have any thoughts why this is happening?
// auth.ts
import 'server-only';

import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { db } from '@/db';
import { captcha, twoFactor } from 'better-auth/plugins';
import { nextCookies } from 'better-auth/next-js';
import { betterAuth } from 'better-auth';
import { config } from 'dotenv';
import { schema } from '@/db/schema';

config({ path: '.env' });

export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: 'pg',
usePlural: true,
camelCase: false,
schema,
}),
emailAndPassword: {
enabled: true,
disableSignUp: true,
},
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60, // in seconds
},
expiresIn: 604800, // 7 days
storeSessionInDatabase: true,
},
rateLimit: {
storage: 'database',
},
appName: 'GN Inventory',
user: {
additionalFields: {
role: {
type: 'string',
required: true,
defaultValue: 'viewer',
input: false,
},
},
},
plugins: [
twoFactor(),
nextCookies(),
captcha({
provider: 'hcaptcha',
siteKey: 'secret',
secretKey: process.env.HCAPTCHA_SECRET!,
}),
],
advanced: {
cookiePrefix: 'gn-inventory',
},
});
// auth.ts
import 'server-only';

import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { db } from '@/db';
import { captcha, twoFactor } from 'better-auth/plugins';
import { nextCookies } from 'better-auth/next-js';
import { betterAuth } from 'better-auth';
import { config } from 'dotenv';
import { schema } from '@/db/schema';

config({ path: '.env' });

export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: 'pg',
usePlural: true,
camelCase: false,
schema,
}),
emailAndPassword: {
enabled: true,
disableSignUp: true,
},
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60, // in seconds
},
expiresIn: 604800, // 7 days
storeSessionInDatabase: true,
},
rateLimit: {
storage: 'database',
},
appName: 'GN Inventory',
user: {
additionalFields: {
role: {
type: 'string',
required: true,
defaultValue: 'viewer',
input: false,
},
},
},
plugins: [
twoFactor(),
nextCookies(),
captcha({
provider: 'hcaptcha',
siteKey: 'secret',
secretKey: process.env.HCAPTCHA_SECRET!,
}),
],
advanced: {
cookiePrefix: 'gn-inventory',
},
});
Does anyone have any ideas why?
No description
Solution:
Session Expiration Limited to 1 Day Despite 7-Day Configuration - B...
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:
sessionExpiresAt: '2025-05-02 19:40:17.627',
sessionCreatedAt: '2025-05-01 19:40:17.628',
timeDiffDays: 0.999999988425926
sessionExpiresAt: '2025-05-02 19:40:17.627',
sessionCreatedAt: '2025-05-01 19:40:17.628',
timeDiffDays: 0.999999988425926
**Relevant...
Jump to solution
1 Reply
Solution
matt
matt5d ago
Session Expiration Limited to 1 Day Despite 7-Day Configuration - B...
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:
sessionExpiresAt: '2025-05-02 19:40:17.627',
sessionCreatedAt: '2025-05-01 19:40:17.628',
timeDiffDays: 0.999999988425926
sessionExpiresAt: '2025-05-02 19:40:17.627',
sessionCreatedAt: '2025-05-01 19:40:17.628',
timeDiffDays: 0.999999988425926
**Relevant...

Did you find this page helpful?