#10928·next-auth

Authjs v5 redirecting to the wrong URL

Author: 0mhxCreated May 15, 2024Updated Sep 4, 2026
Labelsbugtriage

Environment

  System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M2
    Memory: 1019.91 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.6.2 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - /opt/homebrew/bin/npm
    pnpm: 8.15.4 - /opt/homebrew/bin/pnpm
    bun: 1.0.26 - /usr/local/bin/bun
  Browsers:
    Chrome: 124.0.6367.203
    Chrome Canary: 126.0.6478.2
    Safari: 17.5
    Safari Technology Preview: 17.4
  npmPackages:
    next: 14.2.3 => 14.2.3 
    next-auth: 5.0.0-beta.18 => 5.0.0-beta.18 
    react: ^18.2.0 => 18.2.0 

Reproduction URL

https://github.com/spaceness/stardust/ fixed, and project has a rewrite not using auth.js

Describe the issue

When I use Auth.js with an OAuth provider, like in my case Auth0, it redirects to localhost:3000 even if I'm logging in through a VSCode devtunnels or Tailscale funnel. In fact, this issue actually happens on every other URL.

There is an error with the server expecting the tunnel's URL but getting localhost.

How to reproduce

Setup the repository (only the nextauth and the DB stuff), and then try to login with a non localhost URL.

Expected behavior

It should redirect from the initial URL where the attempt was initiated from.