Allow init/generate/migrate without .env #1686

Closed
opened 2026-03-13 08:55:59 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @maelp on GitHub (Aug 12, 2025).

Is this suited for github?

  • Yes, this is suited for github

I'm using a monorepo with a shared project config defined in typescript (so it's typesafe) at @workspace/config, and this is where I'd like to define my BetterAuth config like this:

      ENV: {
        BETTER_AUTH_SECRET: choose({
          development: "SomeRandomSecretString",
          staging: onePassword("staging", "BETTER_AUTH_SECRET"),
          production: onePassword("production", "BETTER_AUTH_SECRET"),
        }),
        BETTER_AUTH_URL: choose({
          development: "http://localhost:3000",
          staging: "https://portal.staging.mycompany.com",
          production: "https://portal.mycompany.com",
        }),
      },

but right now it seems that pnpm npx @better-auth/cli init complains if there is no .env file, with the requested variables, although I'd like to set them in a different way

is there a way to just give set those variables directly in the shell before calling the cli (without the .env), or as args of the cli?

Describe the solution you'd like

Have an alternate way to set those values, for instance define them as environment variables in the current shell, or as parameters pnpm npx @better-auth/cli --secret MySecret etc

Describe alternatives you've considered

Generating a .env on-the-fly, but this is error-prone

Additional context

No response

Originally created by @maelp on GitHub (Aug 12, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I'm using a monorepo with a shared project config defined in typescript (so it's typesafe) at @workspace/config, and this is where I'd like to define my BetterAuth config like this: ```ts ENV: { BETTER_AUTH_SECRET: choose({ development: "SomeRandomSecretString", staging: onePassword("staging", "BETTER_AUTH_SECRET"), production: onePassword("production", "BETTER_AUTH_SECRET"), }), BETTER_AUTH_URL: choose({ development: "http://localhost:3000", staging: "https://portal.staging.mycompany.com", production: "https://portal.mycompany.com", }), }, ``` but right now it seems that `pnpm npx @better-auth/cli init` complains if there is no `.env` file, with the requested variables, although I'd like to set them in a different way is there a way to just give set those variables directly in the shell before calling the `cli` (without the .env), or as args of the cli? ### Describe the solution you'd like Have an alternate way to set those values, for instance define them as environment variables in the current shell, or as parameters `pnpm npx @better-auth/cli --secret MySecret` etc ### Describe alternatives you've considered Generating a .env on-the-fly, but this is error-prone ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 08:55:59 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 12, 2025):

The BetterAuth CLI currently requires a .env file for the init, generate, and migrate commands and does not support passing secrets or URLs as CLI arguments or reading them directly from shell environment variables. The CLI checks for .env files and exits with an error if none are found, and there are no options to override this behavior or provide config via arguments or shell variables (source, docs).

As a workaround, you could programmatically generate a .env file before running the CLI, but this is admittedly error-prone. To support your use case, the CLI would need to be updated to fall back to process.env if no .env file is present, or accept config values as CLI arguments.

If you want to propose this feature, the most direct change would be to relax the .env file requirement in the CLI and allow config to be provided via shell environment variables or CLI flags.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 12, 2025): <!-- Answer --> The BetterAuth CLI currently requires a `.env` file for the `init`, `generate`, and `migrate` commands and does not support passing secrets or URLs as CLI arguments or reading them directly from shell environment variables. The CLI checks for `.env` files and exits with an error if none are found, and there are no options to override this behavior or provide config via arguments or shell variables ([source](https://github.com/better-auth/better-auth/blob/0d16d8e02c52d97725d5781eb1420ef95fc629c1/packages/cli/src/commands/init.ts), [docs](https://better-auth.com/docs/installation)). As a workaround, you could programmatically generate a `.env` file before running the CLI, but this is admittedly error-prone. To support your use case, the CLI would need to be updated to fall back to `process.env` if no `.env` file is present, or accept config values as CLI arguments. If you want to propose this feature, the most direct change would be to relax the `.env` file requirement in the CLI and allow config to be provided via shell environment variables or CLI flags. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/5b1a0f14-9cba-40fd-bc39-a1680966ab88?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/5b1a0f14-9cba-40fd-bc39-a1680966ab88?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/5b1a0f14-9cba-40fd-bc39-a1680966ab88?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/5b1a0f14-9cba-40fd-bc39-a1680966ab88?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/5b1a0f14-9cba-40fd-bc39-a1680966ab88?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/5b1a0f14-9cba-40fd-bc39-a1680966ab88?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/5b1a0f14-9cba-40fd-bc39-a1680966ab88?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3950)
Author
Owner

@Kinfe123 commented on GitHub (Aug 13, 2025):

The CLI is meant to you lonely for development purposes and you still can provide that. other than we currently dont have a plan to support those considering the current CLI usecase.

@Kinfe123 commented on GitHub (Aug 13, 2025): The CLI is meant to you lonely for development purposes and you still can provide that. other than we currently dont have a plan to support those considering the current CLI usecase.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1686