Closed FlorientPlouvin closed 4 months ago
Hi @FlorientPlouvin 👋
I assume that this issue occurs because you have set a different redirect URL in the Google OAuth application.
Please open your Google cloud console and verify the OAuth application redirect URL matches your production URL. Below I posted an example from one of my applications using NuxtAuth (and FushionAuth).
When it comes to the environment variables, I recommend the following:
AUTH_ORIGIN
to: https://MY_DOMAIN.comNEXTAUTH_URL
to: https://MY_DOMAIN.com/api/authauth.baseURL
in the nuxt.config.ts
, as this overwrites the AUTH_ORIGIN
environment variable!
auth.baseURL
sets the URL at build time, while AUTH_ORIGIN
lets you configure it at runtime!
Environment
Working directory: /app
Nuxt project info:
Build Modules: -
Reproduction
Describe the bug
Hello everyone.
I have a problem with my google provider when using it in production. When I want to authenticate with Google in production (so with the url
https://my-prod.com
) it sends me an error 400: redirect_uri_mismatch with its information:redirect_uri=http://localhost:3000/api/auth/callback/google
.After searching, I saw this issue #664 and so I modified my [...].ts to have this
And now I can select my email in google!
But I now have another problem: when I arrive at my callback url, I'm automatically redirected to
http://localhost:3000/api/auth/error?error=OAuthCallback
. with an error in my app:After searching and seeing different issues, I think it's because it couldn't get my AUTH_ORIGIN environment variable (or maybe NEXTAUTH_URL (I tried to put both to hope for a different result but nothing)). Checking the nuxt doc I came across this
Production Preview
After your server is built, you are responsible for setting environment variables when you run the server. Your .env file will not be read at this point. How you do this is different for every environment.
I'm afraid this is what makes all the difference with my dev environment and therefore causes all the errors.
Does anyone have a solution? I'm deeply blocked and can't see what the solution is.
Additional context
My auth part in nuxt.config.ts :
Logs
No response