Cookie is not being set if defaultCookieAttributes path starts with // #784

Closed
opened 2026-03-13 08:04:12 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @krishna-santosh on GitHub (Mar 5, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

set defaultCookieAttributes path to '//' in betterAuth config

Current vs. Expected behavior

Currently it does nothing, and browser ignores path as it is not a valid value for the cookie's path attribute. Resulting in no cookie being set.

Expected:
Log an Error

ERROR [Better Auth]: Invalid defaultCookieAttributes path: //

This helps avoid wasting time on debugging when user makes a mistake.

Something like this is already handled appropriately when callbackURL starts with //.

What version of Better Auth are you using?

1.2.3

Provide environment information

NA

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

export const auth = betterAuth({
  database: prismaAdapter(prisma, { provider: 'postgresql' }),
  socialProviders: {
    google: {
      clientId: process.env.AUTH_GOOGLE_ID,
      clientSecret: process.env.AUTH_GOOGLE_SECRET,
    },
  },
  advanced: {
    defaultCookieAttributes: {
      path: '//',
    },
  },
});

Additional context

No response

Originally created by @krishna-santosh on GitHub (Mar 5, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce set `defaultCookieAttributes` path to '//' in betterAuth config ### Current vs. Expected behavior Currently it does nothing, and browser ignores path as it is not a valid value for the cookie's path attribute. Resulting in no cookie being set. Expected: Log an Error > ERROR [Better Auth]: Invalid defaultCookieAttributes path: // This helps avoid wasting time on debugging when user makes a mistake. Something like this is already handled appropriately when callbackURL starts with //. ### What version of Better Auth are you using? 1.2.3 ### Provide environment information ```bash NA ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: 'postgresql' }), socialProviders: { google: { clientId: process.env.AUTH_GOOGLE_ID, clientSecret: process.env.AUTH_GOOGLE_SECRET, }, }, advanced: { defaultCookieAttributes: { path: '//', }, }, }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 08:04:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#784