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

Public prefix shouldn't be allowed on server variables #56

Closed
Jacob-Lockwood opened this issue May 8, 2023 · 3 comments · Fixed by #68
Closed

Public prefix shouldn't be allowed on server variables #56

Jacob-Lockwood opened this issue May 8, 2023 · 3 comments · Fixed by #68

Comments

@Jacob-Lockwood
Copy link

Jacob-Lockwood commented May 8, 2023

You can accidentally include one of your public environment variables in the server object, preventing you from accessing it on the client even though it is public. There should probably be an error if the server variable section has a public prefix, to prevent this from happening.

For example, this env in NextJS:

export const env = createEnv({
  server: {
    DATABASE_URL: z.string().url(),
    NEXT_PUBLIC_API_KEY: z.string().min(1),
//  ^^^^^^^^^^^^ ideally, this should be an error
  },
  client: {
    NEXT_PUBLIC_OTHER_VARIABLE: z.string().url(),
  },
  runtimeEnv: { ... },
});

Not sure how big of an issue this is but it seems like a good and fairly easy fix. I can send a PR if it would be helpful.

@chungweileong94
Copy link
Contributor

Actually, I don't think this is really necessary tho, you can technically access anything on server-side.

@Jacob-Lockwood
Copy link
Author

I think it might still be good as a warning if people do it accidentally, because if you make this mistake you won't be able to access your environment variables on the client-side.

@chungweileong94
Copy link
Contributor

chungweileong94 commented May 21, 2023

I think it might still be good as a warning if people do it accidentally, because if you make this mistake you won't be able to access your environment variables on the client-side.

Well, you got a point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants