ApplicationError: state mismatch caused by Custom Domains using NextJS

I have set up custom domains on both our staging and production tenants. When I tested it, the flow seemed to work fine.

However, there has been an issue with my setup when I log-in, then log-out, then log-in again. When I try to log-in again, I receive an error on the server saying ApplicationError: state mismatch and the user cannot log in again.

When I disabled Custom Domains (by changing the env var AUTH0_ISSUER_BASE_URL back to the original value), the error disappears and the user can log in as expected.

Is there a NextJS-specific step or setting which needs to be considered as part of the Custom Domains setup?

For SPAs, it seems like there is an additional step of setting the domain when initializing the Auth0 Client (Configure Features to Use Custom Domains). However, for NextJS which is set up as a “Regular Web Application”, there is no documented step.

How can I resolve Custom Domains on NextJS?

We are using NextJS in standalone mode hosted on AWS.

One thing I noticed from past issues is that they used initAuth0 from the SDK and passed in a domain param. (ex. "state mismatch" on nextjs example · Issue #26 · auth0/nextjs-auth0 · GitHub)

However, the most recent version of the SDK no longer supports a domain param. Wondering if that’s related to the issue I’m facing