Better Auth Error Session data is too large to store in the cookie

I'm always getting this error whenever I tried to sign up.
# SERVER_ERROR:  [Error [BetterAuthError]: Session data is too large to store in the cookie. Please disable session cookie caching or reduce the size of the session data] {
  cause: undefined
}


Here's my auth instance
import { db } from '@/db' // your drizzle instance
import { account, session, user, verification } from '@/db/schema/auth'

import { betterAuth } from 'better-auth'
import { drizzleAdapter } from 'better-auth/adapters/drizzle'

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: 'pg', // or "mysql", "sqlite"
    schema: {
      user,
      account,
      session,
      verification
    }
  }),
  emailAndPassword: {
    enabled: true,
    async sendResetPassword(data, request) {
      // Send an email to the user with a link to reset their password
    }
  },
  advanced: {
    generateId: false // Disable default id generation
  }
  session: {
    cookieCache: {
      enabled: true,
      maxAge: 5 * 60 // Cache duration in seconds
    }
  }
})
Solution
This occurs because the base64 of the profile picture is too large. You should upload the profile picture to a S3 bucket or cloudflare R2 and save only the id to the database / cookie
Was this page helpful?