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
},
},
})
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
},
},
})
2 Replies
asmoiseev
asmoiseevOP2w ago
Version 1.2.6 fixed this. Apparently this was causing the issue.
asmoiseev
asmoiseevOP3d ago
Unfortunately no, customSession is still invoked on every request even when cookieCache is enabled.

Did you find this page helpful?