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:

tenant.example.com/api/auth/callback?error=invalid_request&error_description=client%20requires%20organization%20membership%2C%20but%20user%20does%20not%20belong%20to%20any%20organization&state=XXXX...

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?

Thanks!

2 Likes