cookieCache doesn't work with customSession plugin

Hello. I'm wokring on a next.js 15.3 application and noticed that cookieCache doesn't work once I add customSession plugin. I enabled query logging for Prisma client, and see that it queries database on every
getSession()
call. Maybe I'm missing something obvious. Did anyone have similar issues? Here is my config:

export const auth = betterAuth({
  database: prismaAdapter(db, {
    provider: "sqlite",
  }),

  plugins: [
    phoneNumber({
      sendOTP: ({ phoneNumber, code }) => {
        console.log(`Sending OTP code ${code} to ${phoneNumber}`)
      },

      signUpOnVerification: {
        getTempEmail: (phoneNumber) => `${phoneNumber}@my.app`,
      },
    }),

    customSession(async ({ user, session }) => {
      console.info("Custom session callback")

      return {
        roles: ["admin", "manager"],
        session,
      }
    }),

    nextCookies(),
  ],

  // Customize model names to avoid conflicts with existing RedwoodJS tables.
  user: { modelName: "AuthUser" },
  account: { modelName: "AuthAccount", fields: { userId: "authUserId" } },
  verification: { modelName: "AuthVerification" },

  session: {
    modelName: "AuthSession",
    fields: { userId: "authUserId" },

    cookieCache: {
      enabled: true,
      maxAge: 30, //5 * 60, // in seconds
    },
  },
})
Was this page helpful?