How can we use nextauth in google idx

I’ve been trying to implement NextAuth with Google Identity Platform (IDX) for a long time but haven’t been successful. Initially, I tried using the GitHub provider, but I kept getting an error saying that the redirect URL is not authorized.

I asked ChatGPT for help, and it suggested that the issue was due to the temporary URLs used by IDX. I faced the same problem when trying to implement it in Replit.

Then, I decided to use the Google provider, but I encountered the same authorization issue with the redirect URL.

Has anyone successfully set up NextAuth with Google IDX? How did you handle the redirect URL authorization issue? Any help would be greatly appreciated!

I’d recommend testing this locally instead. The issue is that NextAuth in IDX struggles with GitHub/Google providers because:

  1. The workspace URL is temporary and private
  2. OAuth redirects to localhost won’t work since you’re accessing through a forwarded proxy URL

This is a common OAuth configuration challenge in containerized development environments.

Actually my pc is not that strong to work with heavy libarary like next that’s why I use Google idx and also I move from one place to another regular and in between I try to do the work so is there any option that I can do in idx only

Oh hey, I totally get it - I was facing the same problem few years back and did most in GH codespaces.

So I just tested this out myself and got it working! I put together a quick example repo here: GitHub - securethinker295/idx-next-auth: A simple next project which works in IDX with next auth

The trick is super simple:

  1. Make your IDX workspace public (seriously, this is important)
  2. Grab the preview URL that IDX gives you and use that same URL in both your GitHub OAuth settings and your .env file(Copy this from the URL bar after the initial site opens. Don’t copy it from the IDX tab in editor)

Check out the README - it’s pretty straightforward. Just hit “import” in IDX, paste that repo URL, and you’re like 80% there already. Let me know if you get stuck!

Okay thanks I Will try my best