next-forge icon indicating copy to clipboard operation
next-forge copied to clipboard

Dynamic Environment Validation: Introduced Flags for Service-Specific Configuration.

Open DrHazemAli opened this issue 3 months ago • 3 comments

Summary

I really enjoy working on this project. It’s well-designed, and contributing to it feels both rewarding and inspiring. I’m excited to be part of its growth and look forward to helping make it even better!

However, This PR adds a new feature that dynamically validates environment variables based on the services enabled in the .env file. It addresses #228 by simplifying the configuration process and making it more modular for service-specific setups.

Key Changes

  1. Service Enable Flags:

    • Added ENABLE_CLERK, ENABLE_STRIPE, and ENABLE_RESEND flags to enable or disable specific services dynamically.
  2. Dynamic Schema Validation:

    • The server schema now conditionally includes service-specific fields based on the flags' state.
    • Example: If ENABLE_STRIPE=false, STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET are not required.
  3. Improved Modularity:

    • Each app can define only the required variables for its active services, reducing unnecessary configuration complexity.

How to Use

  1. Add the service enable flags to your .env file:

    ENABLE_CLERK=true
    ENABLE_STRIPE=false
    ENABLE_RESEND=true
    
  2. Include the required environment variables for the services you enable:

    # Clerk (if ENABLE_CLERK=true)
    CLERK_SECRET_KEY=sk_your_clerk_secret_key
    CLERK_WEBHOOK_SECRET=whsec_your_clerk_webhook_secret
    
    # Resend (if ENABLE_RESEND=true)
    RESEND_AUDIENCE_ID=your_resend_audience_id
    RESEND_FROM=your_resend_from_email
    RESEND_TOKEN=re_your_resend_token
    
  3. Restart your development server after making changes:

    pnpm dev
    

Benefits

  • Reduces configuration overhead by requiring only the variables for enabled services.
  • Improves flexibility and modularity in managing service-specific configurations.
  • Simplifies the development and deployment workflow.

Related Issues

Closes #228

Checklist

  • [x] My code follows the code style of this project.
  • [x] I have performed a self-review of my code.
  • [x] I have commented my code, particularly in hard-to-understand areas.
  • [x] I have updated the documentation, if necessary.
  • [x] I have added tests that prove my fix is effective or my feature works.
  • [x] New and existing tests pass locally with my changes.

DrHazemAli avatar Nov 16 '24 12:11 DrHazemAli