502 error when hitting auth/login

I have a hosted website running nextjs and am using the nextjs-auth0 module for authentication. This was working fine but hitting auth/login (initially through Google SSO) using a particular browser session results in a 502 error. The same exact process works fine in a new window (with a different generated state of course). Any idea of why this is happening?

Using Chrome 95 on Mac OS.

Hi @keithg,

Welcome to the Auth0 Community!

Can you please provide some more detail? What request is returning the error? You can use Google’s developer tools to see what is happening:

Thank you Dan.

When trying to sign in the Auth0 callback calls my nextjs /api/auth/callback api route which executes the callback method in the nextjs-auth0 package. This is returning a 502.

Can you please share a codeblock with the function that is causing this?

It simply performs a call to handleLoginWindowOpener function.

  const handleLoginWindowOpener = async () => {
    window.open('/login/api/auth/logout','_blank');
  }

  // ----------------------------------------------------

  return (
    <header>
      <span className="text-md text-pink">
        <button onClick={handleLoginWindowOpener}>{sessionInfo.user ? 'Click to logout.' : 'Click to login or to create an account.'}</button>
      </span>
      <span className="text-md text-gray">
        {' | '}{hostname} {sessionInfo.token?.expiry ? ` (current login valid till ${timestampToDateString(sessionInfo.token.expiry)})` : ' (logged out)'}
      </span>
    </header>
  )
}

Issue happens on one particular instance after attempting to/signing in using Google. There is nothing in the nginx logs either, seems like the call didn’t reach the server.

The route you are using looks a bit odd, typically we see /api/auth/logout, instead of /login/api/auth/logout. Is it possible this route is causing the issue?

The /login/ route is being captured by nginx and forwarded accordingly (correct route/port). I’ve never encountered any issues apart from this specific instance and it works as expected if opened in a new window.

Can you please DM me a HAR of a failed request?

2 Likes

This ended up being an issue with an older version of the nextjs-auth0 SDK. Resolved by upgrading to the latest version.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.