[GH-ISSUE #1118] Please set BETTER_AUTH_SECRET in your environment variables or pass secret in your auth config. #8603

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

Originally created by @jeffscottward on GitHub (Jan 4, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1118

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Setup very basic Astro.js and Better-Auth.
Run Astro.js preview command astro preview or similar depending on your choice of pnpm or npm etc

Current vs. Expected behavior

To not throw an error. I tried adding the secret to the config, and that didn't help either.

What version of Better Auth are you using?

latest as of Jan 3 2025

Provide environment information

Mac OS M1 Sonoma 14.6.1

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

Other

Auth config (if applicable)

export const auth = betterAuth({
  database: {
    dialect,
    type: "sqlite",
  },
  plugins: [
    magicLink({
      expiresIn: 5 * 60, // 5 minutes
      sendMagicLink: async ({ email, token, url }, request) => {
        await sendReactEmail({
          to: email,
          subject: "Sign in to site",
          text: `Click this link to sign in to site: ${url}`,
          template: MagicLinkEmail({
            magicLink: url,
          }),
        });
      },
    }),
  ],
});

Additional context

.env

BETTER_AUTH_URL=https://sampleurl.com
BETTER_AUTH_SECRET=QD2loiXIqtE8q1ES3Y5VVERFxlkqfLt7

terminal

astro preview

19:15:10 [@astrojs/node] Server listening on http://localhost:4321

[Better Auth] ERROR You are using the default secret. Please set BETTER_AUTH_SECRET in your environment variables or pass secret in your auth config.

Originally created by @jeffscottward on GitHub (Jan 4, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1118 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Setup very basic Astro.js and Better-Auth. Run Astro.js preview command `astro preview` or similar depending on your choice of `pnpm` or `npm` etc ### Current vs. Expected behavior To not throw an error. I tried adding the secret to the config, and that didn't help either. ### What version of Better Auth are you using? latest as of Jan 3 2025 ### Provide environment information ```bash Mac OS M1 Sonoma 14.6.1 ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: { dialect, type: "sqlite", }, plugins: [ magicLink({ expiresIn: 5 * 60, // 5 minutes sendMagicLink: async ({ email, token, url }, request) => { await sendReactEmail({ to: email, subject: "Sign in to site", text: `Click this link to sign in to site: ${url}`, template: MagicLinkEmail({ magicLink: url, }), }); }, }), ], }); ``` ### Additional context .env BETTER_AUTH_URL=https://sampleurl.com BETTER_AUTH_SECRET=QD2loiXIqtE8q1ES3Y5VVERFxlkqfLt7 terminal > astro preview 19:15:10 [@astrojs/node] Server listening on http://localhost:4321 [Better Auth] ERROR You are using the default secret. Please set BETTER_AUTH_SECRET in your environment variables or pass secret in your auth config.
GiteaMirror added the lockedbug labels 2026-04-13 03:43:08 -05:00
Author
Owner

@Scooter1337 commented on GitHub (Jan 4, 2025):

Make sure your .env file contents are loaded into process.env using e.g.

dotenv.config();

Or something similar.

<!-- gh-comment-id:2569977481 --> @Scooter1337 commented on GitHub (Jan 4, 2025): Make sure your `.env` file contents are loaded into `process.env` using e.g. ```typescript dotenv.config(); ``` Or something similar.
Author
Owner

@jeffscottward commented on GitHub (Jan 4, 2025):

It’s automatic. See the Astro.js docs
https://docs.astro.build/en/guides/environment-variables/


Jeff Scott Ward
Founder / A.I. & U.I. Engineer
F0.ai

On Fri, Jan 3, 2025 at 8:07 PM L.A. Verheul @.***>
wrote:

Make sure your .env file contents are loaded into process.env using e.g.

dotenv.config();

Or something similar.


Reply to this email directly, view it on GitHub
https://github.com/better-auth/better-auth/issues/1118#issuecomment-2569977481,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAJUO7UJKVQXV5MMVRACPD32I4X4HAVCNFSM6AAAAABUSRBRPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNRZHE3TONBYGE
.
You are receiving this because you authored the thread.Message ID:
@.***>

<!-- gh-comment-id:2569996413 --> @jeffscottward commented on GitHub (Jan 4, 2025): It’s automatic. See the Astro.js docs https://docs.astro.build/en/guides/environment-variables/ ------------------------------ Jeff Scott Ward Founder / A.I. & U.I. Engineer *F0.ai* ------------------------------ On Fri, Jan 3, 2025 at 8:07 PM L.A. Verheul ***@***.***> wrote: > Make sure your .env file contents are loaded into process.env using e.g. > > dotenv.config(); > > Or something similar. > > — > Reply to this email directly, view it on GitHub > <https://github.com/better-auth/better-auth/issues/1118#issuecomment-2569977481>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AAJUO7UJKVQXV5MMVRACPD32I4X4HAVCNFSM6AAAAABUSRBRPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNRZHE3TONBYGE> > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> >
Author
Owner

@Scooter1337 commented on GitHub (Jan 4, 2025):

It’s automatic. See the Astro.js docs https://docs.astro.build/en/guides/environment-variables/

Astro (Vite) loads them into import.meta.env, while better-auth uses process.env. That might be the inconsistency here?

<!-- gh-comment-id:2569998130 --> @Scooter1337 commented on GitHub (Jan 4, 2025): > It’s automatic. See the Astro.js docs https://docs.astro.build/en/guides/environment-variables/ Astro (Vite) loads them into import.meta.env, while better-auth uses process.env. That might be the inconsistency here?
Author
Owner

@jeffscottward commented on GitHub (Jan 4, 2025):

I tried the import meta method but it still didn’t take which really
surprised me and why I did file this bug.


Jeff Scott Ward
Founder / A.I. & U.I. Engineer
F0.ai

On Fri, Jan 3, 2025 at 8:54 PM L.A. Verheul @.***>
wrote:

It’s automatic. See the Astro.js docs
https://docs.astro.build/en/guides/environment-variables/

Astro (Vite) loads them into import.meta.env, while better-auth uses
process.env. That might be the inconsistency here?


Reply to this email directly, view it on GitHub
https://github.com/better-auth/better-auth/issues/1118#issuecomment-2569998130,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAJUO7QY4SDC7JNUNWNJIKT2I45MNAVCNFSM6AAAAABUSRBRPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNRZHE4TQMJTGA
.
You are receiving this because you authored the thread.Message ID:
@.***>

<!-- gh-comment-id:2570022242 --> @jeffscottward commented on GitHub (Jan 4, 2025): I tried the import meta method but it still didn’t take which really surprised me and why I did file this bug. ------------------------------ Jeff Scott Ward Founder / A.I. & U.I. Engineer *F0.ai* ------------------------------ On Fri, Jan 3, 2025 at 8:54 PM L.A. Verheul ***@***.***> wrote: > It’s automatic. See the Astro.js docs > https://docs.astro.build/en/guides/environment-variables/ > > Astro (Vite) loads them into import.meta.env, while better-auth uses > process.env. That might be the inconsistency here? > > — > Reply to this email directly, view it on GitHub > <https://github.com/better-auth/better-auth/issues/1118#issuecomment-2569998130>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AAJUO7QY4SDC7JNUNWNJIKT2I45MNAVCNFSM6AAAAABUSRBRPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNRZHE4TQMJTGA> > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> >
Author
Owner

@ericclemmons commented on GitHub (Mar 21, 2025):

Similar setup, but I was able to confirm it works by passing secret:

export const auth = betterAuth({
  database: drizzleAdapter(db, { provider: "pg" }),
  emailAndPassword: {
    enabled: true,
  },
  secret: import.meta.env.BETTER_AUTH_SECRET,
});

I'd investigate there with console.info(...) and make sure it's being explicitly passed and all.

<!-- gh-comment-id:2743693329 --> @ericclemmons commented on GitHub (Mar 21, 2025): Similar setup, but I was able to confirm it works by passing `secret`: ```js export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg" }), emailAndPassword: { enabled: true, }, secret: import.meta.env.BETTER_AUTH_SECRET, }); ``` I'd investigate there with `console.info(...)` and make sure it's being explicitly passed and all.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8603