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',
  },
});


Does anyone have any ideas why?
CleanShot_2025-10-15_at_15.54.13.png
Solution
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


**Relevant...
Was this page helpful?