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

feat: make packages pure and only validate env's in apps #397

Open
amirfakhrullah opened this issue Jun 4, 2023 · 5 comments
Open

feat: make packages pure and only validate env's in apps #397

amirfakhrullah opened this issue Jun 4, 2023 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@amirfakhrullah
Copy link

amirfakhrullah commented Jun 4, 2023

Describe the feature you'd like to request

From the template, we're using t3-env validations separately in apps/nextjs and packages/auth. If I want to use the environment variables in packages/api then I need to set up t3-env validations separately for that workspace. This looks like a duplicated code and I think we should refactor it.

Describe the solution you'd like to see

I suggest to put the t3-env validations in packages/config or in a new workspace, then other workspaces like apps/nextjs, packages/db, packages/auth and packages/api can just import it whenever they want to use them.

Additional information

I would love to work on this if you guys agree to pick this up

Similar issue - #385

@amirfakhrullah amirfakhrullah changed the title feat: Add t3-env validation in packages/config feat: Add t3-env validations in packages/config Jun 4, 2023
@cjkihl
Copy link
Contributor

cjkihl commented Jul 11, 2023

Hi! I was running into the same problem. There's indeed tedious to have env variable validation in multiple packages and if you want to use the same env variable in another package, you have to run validation again.

My question is: Why should packages/auth and packages/api have env variables in the first place? They are packages, not runnable applications. In the same way you download a package from npm, it will not read your .env file, instead you give it variables as parameters.

Personally, I would rather have packages more pure, and only have env variables in the expo and nextjs application. Then pass them on as parameters to other packages.

For Example in apps/nextjs/src/pages/api/trpc/[trpc].ts we can pass all config as parameters to a factory method:
image

Any suggestions or ideas @juliusmarminge ?

@juliusmarminge
Copy link
Member

juliusmarminge commented Jul 15, 2023

Personally, I would rather have packages more pure, and only have env variables in the expo and nextjs application. Then pass them on as parameters to other packages.

I'd like that too, however I'm not sure how to implement that in a nice way. Open for PRs!

I don't want a separate @acme/env package. Either the package itself validates what it needs, or we keep envs in the apps and only validate there

@juliusmarminge juliusmarminge added the enhancement New feature or request label Jul 15, 2023
@juliusmarminge juliusmarminge changed the title feat: Add t3-env validations in packages/config feat: make packages pure and only validate env's in apps Jul 15, 2023
@juliusmarminge juliusmarminge added the help wanted Extra attention is needed label Jul 15, 2023
@dBianchii
Copy link
Contributor

I thought about this as well while dealing with envs. I agree with @cjkihl that it is better if we only have env variables in the expo and nextjs applications.

@RobRoseKnows
Copy link

I've also ran into this issue replacing the @vercel/postgres package with a generic postgres package in Drizzle. I honestly think the best bet is creating an acme/env package, I'm curious as to why you're against it @juliusmarminge

@jancbeck
Copy link

jancbeck commented Sep 2, 2024

wondering why packages/db doesn't validate env but packages/auth does @juliusmarminge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants