Issue with environment variables that are correctly set
SolvedClosed
(edited)
Hi. Login with Google works locally, but doesn't work in production. I receive an error: "Access blocked: Authorization Error. The OAuth client was not found. Error 401: invalid_client"
I set up env variables in the Settings > Environment Variables: AUTH_GOOGLE_ID and AUTH_GOOGLE_SECRET
I checked a few times whether all the values are correct. I also redeployed the last branch (google-auth) a few times when I tried to solve the problem. Didn't help.
I use Auth.js and that's how the env variables look in the code:
Google({
clientId: process.env.AUTH_GOOGLE_ID,
clientSecret: process.env.AUTH_GOOGLE_SECRET,
})
Please, help me to solve this problem. Thank you.
Vercel Alum
Hi ! Welcome to the Vercel Community 😊
Here are a few steps you can try to troubleshoot the issue:
1. Verify Your Environment Variables
Let’s make sure your environment variables are set up correctly in Vercel:
Head to your Vercel dashboard and select your project.
Go to Settings > Environment Variables.
Double-check that AUTH_GOOGLE_ID and AUTH_GOOGLE_SECRET are entered correctly. Watch out for any extra spaces before or after the values!
2. Redeploy with Updated Variables
After verifying the environment variables:
Open the Deployments tab in your Vercel dashboard.
Find your latest deployment.
Click the three dots (...) next to it and select Redeploy.
This ensures the updated environment variables are applied.
3. Log Environment Variable Access
To confirm your app is accessing these variables, you can temporarily log them in your code. (Be cautious not to expose sensitive data in production logs!) Here's an example:
I added NEXTAUTH_URL with different values to different environments. http://localhost:3000 for my local variable and https://personal-task-manager-nine.vercel.app/ for my production variable - Settings > Environmental variables.
After that I pushed the changes and saw that everything started to work
Thank you again.
Vercel Alum
I'm glad it worked out for you, !
This topic is closed. It no longer accepts new replies.