URI callback redirects to deploy build and not domain site

I’m working with next-auth to have users use Google SSO to sign into my app. I’ve done this before on Netlify but something is off about the build.

My site is at: https://cds-social.netlify.app and the repo is https://github.com/ryanjames1729/cds-social. According to the docs, the callback url for Google SSO should be */api/auth/callback/google, where * is your domain. But, when my app tries to authorize a user, Netlify is redirecting the callback to –/api/auth/callback/google rather than /api/auth/callback/google.

This can be seen in my production app which calls back to build: https://6334efa71a19b41d101fa5d2–cds-social.netlify.app/ rather than https://cds-social.netlify.app

To make it work I have to go into my Google App settings and update the URI Callback each time I deploy a new update to Netlify. Any ideas on how to fix this?

Hey there, @rjames

Thanks for your patience here! It has been a few days-- are you still encountering difficulties?

If you are, can you try taking a look at your environment variables (starting with NEXTAUTH_URL) and making sure it is set to the right path? This will help you make sure that you are configured correctly. We found documentation here that may be helpful: Options | NextAuth.js


Hillary, thanks for getting back to me. No, unfortunately, I’m having the same issue. It’s weird because I’ve done this before with no hiccups. It’s something going on with this prod build.

Hey @rjames,

Is it possible for you to add me to the list of allowed users on your Google Auth part? At the moment, we cannot check the problem live because it’s restricted to your org. I’ll share my email address in a DM.

Hey @rjames,

Thanks for adding me to your app, I tried it and I don’t seem to be getting redirected to the incorrect page. I’m seeing this:

Yeah, that has happened once before after a build. But that is still an example of redirecting to the wrong callback url. Shouldn’t it stay on the original subdomain cds-social and not redirect to main--cds-social?

I believe you’ve set your NextAuth environment variable as main--cds-social.