Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Enhance repo/env with Granular Service-Based Environment Variable Validation #228

Open
enolcasielles opened this issue Nov 14, 2024 · 3 comments · May be fixed by #252
Open
Labels
enhancement New feature or request

Comments

@enolcasielles
Copy link

Currently, the repo/env package enforces validation of all required environment variables for the different services involved (Clerk, Stripe, Resend, etc.), which means that all applications or packages using repo/env must define all environment variables, regardless of whether they need them or not. I have seen an issue suggesting the creation of a symlink to a file at the project root, which I believe is a very good solution to improve the development experience. However, this approach would still leave some issues unresolved.

Proposed Solution

I propose a more granular solution that allows grouping environment variables by service. The idea is to use boolean flag variables to enable or disable specific services at the application level. By default, services would be disabled. Each app would first set the flag variable of the required service to true and then define the necessary variables for that service. The repo/env package would evaluate which services are active and would configure the validation schema accordingly.

This approach would:

  1. Allow each application to activate only the services it requires through the corresponding flags.
  2. Ensure each application only defines the environment variables relevant to the active services.

Next Steps

If this proposal is of interest, I am willing to create a PR with the necessary changes to implement it.

@haydenbleasel
Copy link
Owner

Hey @enolcasielles cool idea! Definitely open to checking out a PR that implements this.

@haydenbleasel haydenbleasel added the enhancement New feature or request label Nov 14, 2024
DrHazemAli added a commit to DrHazemAli/next-forge that referenced this issue Nov 16, 2024
Added Flags: ENABLE_CLERK, ENABLE_STRIPE, ENABLE_RESEND.
Dynamic Validation: The server schema includes service-specific fields only if their respective flags are enabled.
Improved Modularity: This allows for better control over which services are active and their corresponding required variables.
@DrHazemAli
Copy link

Feature added on PR #252

@enolcasielles
Copy link
Author

I’d suggest something like this. This approach remains compatible with previous versions. If the ENABLE_SERVICES_FLAGS environment variable is not defined, everything works as it did before. Alternatively, we could modify this behavior and make flag variables mandatory. I’d like to hear your thoughts on which approach is better, @haydenbleasel.

In any case, when this behavior is enabled, the functionality is straightforward: all variables are divided into services. The user must specify which services a single app needs to use. Once a service is enabled, all related variables are checked.

The commit also includes a sample env.example file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants