Next-Auth client functionality on Vite #7974
Replies: 3 comments
-
|
Doing something similar in my project now as workaround, but should be fixed in this lib I think. |
Beta Was this translation helpful? Give feedback.
-
|
So, much better solution, kind of, would require minimal changes to next-auth. This would quite literally get auth to work out of the box if it wasn't for this line in _utils.ts. I understand the want to be lean with writing code, but even when using Is there any reason why this can't be the following? Using this with |
Beta Was this translation helpful? Give feedback.
-
|
Got it working quite nicely with this elegant solution. Just make sure you have |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been using
@auth/coreto implement authentication in our Serverless Framework/React Vite stack.From the API side, everything was pretty smooth. However when attempting to use the
next-authcomponents and hooks I was met with theprocess is not definederror.This is because Vite uses
import.meta.envinstead ofprocess.env(https://vitejs.dev/guide/env-and-mode.html).I ended up copying over the SessionProvider, useSession and the signin/signout functions into our codebase, but I think it would pretty easy to internally support both Webpack and Vite. For example:
Would allow both bundlers to access
getEnv().NEXTAUTH_URLwithout breaking the current implementation.Vite then needs some extra config to pass the Env correctly, since Vite only exposes variables that are prefixed with
VITE_to the client:And it should just work. Thoughts? Worth doing?
Beta Was this translation helpful? Give feedback.
All reactions