Handle "client requires organization membership" error

We’re running a multi-tenant setup with organizations. Invitations are required for membership, and we only offer social logins. We use a custom domain. When a user tries to login who does not have an invitation, they get redirected to:


We are using the auth0 nextjs library, and I’m not doing any customization of the callback function. This results in an endless loop. Can anyone help me understand:

a) how to avoid the endless loop
b) ideally, how to return the user to the login page with a helpful error message in the universal login experience?