Cookie cache not working on dev
Hi everyone, I'm trying to enable the
once I try to log in in dev, its not working.
My api is running in localhost:4000 and my client in localhost:5173.
Once I click sing in with google, I get redirected but calling
I'm using better-auth
PS: Attached image of the cookies.
cookieCachecookieCache option but once I try to log in in dev, its not working.
My api is running in localhost:4000 and my client in localhost:5173.
Once I click sing in with google, I get redirected but calling
getSessiongetSession on the server returns nullnull.I'm using better-auth
v1.4.7v1.4.7 (latest).PS: Attached image of the cookies.
const authInstance = betterAuth({
secret: env.AUTH_SECRET,
baseURL: env.API_URL,
trustedOrigins: [env.CORS_ORIGIN || 'http://localhost:5173'],
database: drizzleAdapter(db, {
provider: 'pg',
schema: {
// auth
users,
sessions,
accounts,
verifications,
// authz
organizations,
members,
invitations,
},
usePlural: true,
}),
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60, // 5 minutes
version: "0.0.1",
strategy: 'compact',
},
},
advanced: {
useSecureCookies: env.APP_ENV !== 'local',
cookiePrefix:
env.APP_ENV === 'production' ? 'better-auth' : 'dev-better-auth',
crossSubDomainCookies: {
enabled: env.APP_ENV !== 'local',
domain: `.${new URL(env.CORS_ORIGIN).hostname}`,
},
database: {
generateId: false,
},
},
emailAndPassword: {
enabled: true,
},
socialProviders: {
google: {
clientId: env.AUTH_GOOGLE_ID,
clientSecret: env.AUTH_GOOGLE_SECRET,
prompt: 'select_account',
},
},
databaseHooks: {
user: {
create: {
after: async (user) => {
if (opts?.hooks?.onUserCreated) {
await opts.hooks.onUserCreated(user);
}
},
},
},
},
plugins: [organization()],
});const authInstance = betterAuth({
secret: env.AUTH_SECRET,
baseURL: env.API_URL,
trustedOrigins: [env.CORS_ORIGIN || 'http://localhost:5173'],
database: drizzleAdapter(db, {
provider: 'pg',
schema: {
// auth
users,
sessions,
accounts,
verifications,
// authz
organizations,
members,
invitations,
},
usePlural: true,
}),
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60, // 5 minutes
version: "0.0.1",
strategy: 'compact',
},
},
advanced: {
useSecureCookies: env.APP_ENV !== 'local',
cookiePrefix:
env.APP_ENV === 'production' ? 'better-auth' : 'dev-better-auth',
crossSubDomainCookies: {
enabled: env.APP_ENV !== 'local',
domain: `.${new URL(env.CORS_ORIGIN).hostname}`,
},
database: {
generateId: false,
},
},
emailAndPassword: {
enabled: true,
},
socialProviders: {
google: {
clientId: env.AUTH_GOOGLE_ID,
clientSecret: env.AUTH_GOOGLE_SECRET,
prompt: 'select_account',
},
},
databaseHooks: {
user: {
create: {
after: async (user) => {
if (opts?.hooks?.onUserCreated) {
await opts.hooks.onUserCreated(user);
}
},
},
},
},
plugins: [organization()],
});