Next.js Discord

Discord Forum

[NextAuth] Multiple RedirectUri - LoadBalancer

Unanswered
Filipino Venus posted this in #help-forum
Open in Discord
Filipino VenusOP
Hello,
I'm in a situation where I have an app deploy that is both
* publicly exposed via a DNS
* reachable from an internal network with another DNS

trying to sign-in with the DNS matching the AUTH_URL works
and with the other one i'm getting:
Server error
There is a problem with the server configuration.

Check the server logs for more information.


I'm wondering what's the way to "properly" deal with scenario like this ?

If possible i'd like to avoid doing URL REWRITING and having to choose a single DNS working and rewriting anything else to that URL

61 Replies

Filipino VenusOP
🦆
Filipino VenusOP
it doesn't gives en error, the .env is set with a specifc URL
which is the browser facing one
but if your app have it own computer DNS and also the LB DNS
you want to redirect back the user to the place he came from
ah so u want a way to dynamically change your env?
Filipino VenusOP
not exactly
I want to redirect to the url he used to come from
the fact that AUTH_URL is an env is a side effect
if it can be done without an ENV it's fine and probably better in fact
the app allow multi DNS queries
another classic way is that:
tenantA.app.com
tenantB.app.com
let's say you get the tenant list in DB for DNS lookup or whatever
you can't have that done statically
it always needs to redirect back to where it was originally done
@Filipino Venus I want to redirect to the url he used to come from
u can read the request headers to redirect him back to the original place
if thats what u searching
Filipino VenusOP
do you have a page docs of nextauth that shows that specific url intercept for that ? before it get sent to the IDP
when i tried doing that with the AzureAd one last year i ended up messing stuff because there's mutliple call back layer and wasn't sure there
because it's all internally done per vendor right ?
@auth/entra ... @auth/google etc ...
@gin u can read the request headers to redirect him back to the original place
Filipino VenusOP
this should be done within here is that what you're saying ?
uhm
yeah
i think u need the redirect callback
this should be responsible for login and logout redirects
now u need a way to access the headers there
uhm
Filipino VenusOP
this is the part where i'm missing something obvious, i though baseUrl were gonna be localhost as it comes from the browser
    redirect?: (params: {
      /** URL provided as callback URL by the client */
      url: string
      /** Default base URL of site (can be used as fallback) */
      baseUrl: string
    }) => Awaitable<string>
check this
u can get the request object like this
Filipino VenusOP
cool, I'll take a look at that thx
@gin https://next-auth.js.org/configuration/initialization#advanced-initialization
Filipino VenusOP
feels like once you've set AUTH_URL it always override the code later on for url and baseUrl -_-'
or does nextauth detect that automatically
u probably need to check how to pass it manually
then u can easily modify it dynamically
@gin are u passing AUTH_URL somewhere in your config?
Filipino VenusOP
it was still there on my image, removing it + adding that callback might solve the issue
i'll be reading the "advanced init" you sent as well
my guess is that when we tried 1 year ago it was because of the ENV VAR being set
oO wait
      /** URL provided as callback URL by the client */
      url: string
"by the client"
does it imply a component with a use client that might sends that ?
probably yeah
Filipino VenusOP
welp
  const handleSignIn = () => {
    signIn('microsoft-entra-id', { callbackUrl: '/dashboard' });
  };
i'm surprised i don't see the /dashboard "from the other side"
it's try full url
/dashboard here just do navigation, doesn't look like it's passed as redirect uri to the idp
thx a lot @gin got things to try now
no problem!