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

Usage of process.env in Nuxt #751

Closed
puzzle-it-nu opened this issue May 6, 2024 · 4 comments
Closed

Usage of process.env in Nuxt #751

puzzle-it-nu opened this issue May 6, 2024 · 4 comments
Assignees
Labels
enhancement An improvement that needs to be added p3 Minor issue

Comments

@puzzle-it-nu
Copy link

Environment

First of all thanks for all you hard work, really appreciate it.

Reproduction

Its an issue about documentation, so rather hard to reproduce :-)

Describe the bug

The following came up during a discussion with a new team member on our Nuxt3 project. According to the Nuxt documentation you shouldn't use process.env to get at environment variables.
What happens if you build for a deployment that doesn't have a process object just like SSR doesn't have a windows object.

Shouldn't this example use Nuxt3 best practices?

If you agree I'm willing to write a PR for this instance and also for other instances if there are any.

Additional context

No response

Logs

No response

@puzzle-it-nu puzzle-it-nu added bug A bug that needs to be resolved pending An issue waiting for triage labels May 6, 2024
@zoey-kaiser
Copy link
Member

Hi @puzzle-it-nu 👋

I agree with your take here! However, we have to be careful. As we use NextAuth under the hood, certain environment variables need to be set via process.env to allow NextAuth to access these. One of these is e.g. NEXTAUTH_URL.

I have had reworking the environment variables and configuration for NuxtAuth on my list for a while, as I feel that at the moment it is very difficult to properly assess which environment variables need to be set for which provider. I would love to work with you on improving this!

In my opinion, we should begin by outlining which configuration and environment variables are required for which settings and how we can make them feel more native to Nuxt. I also know that we still have a few PR opens that also touch the environment variables (notably: #711). In addition to this, I think we need to update the docs and properly outline the possibilities for how configurations can be set. There is often confusion about this (See: #368)

In conclusion: I would love to receive some help from you on this issue! I personally would propose that we as a first step outline the changes and get a proper overview of what could be improved. Afterward, it would be amazing, if you opened a PR to account for these. Alternately, you can also immediately open a PR, however we may request substantial changes, depending on the changes!

If I can support you in any, feel free to ping me on GitHub or add me on discord (zoeykaiser) 😊

@zoey-kaiser zoey-kaiser added p3 Minor issue enhancement An improvement that needs to be added and removed bug A bug that needs to be resolved pending An issue waiting for triage labels May 9, 2024
@puzzle-it-nu
Copy link
Author

Thanks for the heads up and detailing some of the difficulties that I didn't know about.

My, naive, thinking was that using only useRuntimeConfig() should work but I can imagine that some parts of the code really depend on process.env being available. Those parts that don't should be able to use useRuntimeConfig and I think the docs should reflect that.

I have read the mentioned PR and issue and I wonder whether it would be possible to come up with reproductions and/or a table listing working/not working combinations. Right now I have a hard time keeping track of what works and what doesn't.

Personally I haven't had the above mentioned problems but that doesn't mean they don't exist.

I'm gone on a 2 week vacation and hope to have time after that to look into it.

@zoey-kaiser
Copy link
Member

Potentially resolved by #837

@zoey-kaiser
Copy link
Member

Closing as in #837 we now switched to a more flexible approach where both normal and Nuxt environment variables can be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement that needs to be added p3 Minor issue
Projects
None yet
Development

No branches or pull requests

3 participants
@puzzle-it-nu @zoey-kaiser and others