sidebase / nuxt-auth

🔐 Nuxt user authentication and sessions via authjs (next-auth), local and refresh providers. nuxt-auth wraps NextAuth.js to offer the reliability & convenience of a 12k star library to the nuxt 3 ecosystem with a native developer experience (DX)
https://sidebase.io/nuxt-auth/
MIT License
1.12k stars 134 forks source link

Usage of process.env in Nuxt #751

Open puzzle-it-nu opened 1 month ago

puzzle-it-nu commented 1 month ago

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

zoey-kaiser commented 1 month ago

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: https://github.com/sidebase/nuxt-auth/pull/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: https://github.com/sidebase/nuxt-auth/issues/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) 😊

puzzle-it-nu commented 1 month ago

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.