Cookie not persisting on client

I am testing better-auth with a frontend on http://localhost:5173 and a backend on hono + aws lambda. The request works but the cookie is not being persisted in the browser. On the client I have a pretty standard configuration
export const { signIn, signOut, signUp, useSession, emailOtp } = createAuthClient({
baseURL: import.meta.env.VITE_BETTER_AUTH_URL ?? '',
plugins: [emailOTPClient()],
fetchOptions: { credentials: 'include' }
});
export const { signIn, signOut, signUp, useSession, emailOtp } = createAuthClient({
baseURL: import.meta.env.VITE_BETTER_AUTH_URL ?? '',
plugins: [emailOTPClient()],
fetchOptions: { credentials: 'include' }
});
and my server looks like
export const auth = betterAuth({
database: drizzleAdapter(db, { provider: 'pg', schema: { ...authSchema } }),
emailAndPassword: {
enabled: true,
},
// advanced: {
// cookies: {
// session_token: {
// attributes: {
// sameSite: 'none',
// path: '/',
// httpOnly: true,
// secure: true
// }
// }
// }
// },
trustedOrigins: ['http://localhost:5173'],
});
export const auth = betterAuth({
database: drizzleAdapter(db, { provider: 'pg', schema: { ...authSchema } }),
emailAndPassword: {
enabled: true,
},
// advanced: {
// cookies: {
// session_token: {
// attributes: {
// sameSite: 'none',
// path: '/',
// httpOnly: true,
// secure: true
// }
// }
// }
// },
trustedOrigins: ['http://localhost:5173'],
});
Am I missing something? This is a react + vite SPA
2 Replies
Maqed
Maqed2mo ago
I have the same problem but with Express.js. The problem only occurs in my mobile Chrome browser (without enabling incognito mode). If incognito mode is enabled or using a different browser, the cookie persists on client. I tried deleting all of the cookies and trying logging in but still in vain.
bill92
bill92OP5w ago
no luck yet, I'll post here if I have a solution

Did you find this page helpful?