secure cookies not being set on production #911

Closed
opened 2026-03-13 08:09:38 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @PolarBearEs on GitHub (Mar 25, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Create a next app and deploy to Vercel without BETTER_AUTH_URL

Current vs. Expected behavior

Problems with secure cookies.
When deploying to prod, cookies are not set to secure if BETTER_AUTH_URL is not set.
I assume is becouse createCookieGetter is not resolving to the else condition based on the defaults

What version of Better Auth are you using?

1.2.4

Provide environment information

Next.js app
Deployed on Vercel
Using only google sign in

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

Package, Client

Auth config (if applicable)

export const auth =
    betterAuth({
        database: surrealAdapter(db),
        socialProviders: {
            google: {
                clientId: process.env.GOOGLE_CLIENT_ID as string,
                clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
            },
        },
    });

Additional context

No response

Originally created by @PolarBearEs on GitHub (Mar 25, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Create a next app and deploy to Vercel without BETTER_AUTH_URL ### Current vs. Expected behavior Problems with secure cookies. When deploying to prod, cookies are not set to secure if BETTER_AUTH_URL is not set. I assume is becouse createCookieGetter is not resolving to the else condition based on the defaults ### What version of Better Auth are you using? 1.2.4 ### Provide environment information ```bash Next.js app Deployed on Vercel Using only google sign in ``` ### Which area(s) are affected? (Select all that apply) Package, Client ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: surrealAdapter(db), socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, }, }, }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 08:09:38 -05:00
Author
Owner

@PolarBearEs commented on GitHub (Mar 25, 2025):

Also docs state that baseulr: If not explicitly set, the system will check for the environment variable process.env.BETTER_AUTH_URL. If not set, it will throw an error.

But also states
Set Environment Variables
Create a .env file in the root of your project and add the following environment variables:
...
Set Base URL (optional)
BETTER_AUTH_URL=http://localhost:3000 #Base URL of your app

@PolarBearEs commented on GitHub (Mar 25, 2025): Also docs state that baseulr: [If not explicitly set, the system will check for the environment variable process.env.BETTER_AUTH_URL. If not set, it will throw an error. ]( https://www.better-auth.com/docs/reference/options#baseurl) But also states [Set Environment Variables](https://www.better-auth.com/docs/installation#set-environment-variables) Create a .env file in the root of your project and add the following environment variables: ... **Set Base URL (optional)** BETTER_AUTH_URL=http://localhost:3000 #Base URL of your app
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#911