Cannot read properties of undefined (reading 'returnTo')

Hi I have been working on the organisation flow and I have currently got it working by inviting a member through the Auth0 Dashboard and opening the email. It correctly shows the organisation sign up form, I complete the form, complete the 2FA step, it then shows me the authorise step for handling the scopes. After accepting that is when I hit the error. It’s just a black screen with the message:

Cannot read properties of undefined (reading 'returnTo')

As shown in the screenshot. It looks correct as a code is returned in the URL and I can confirm that the user is created and is now a member of the organisation, which is great. I can ignore the message and login as the new user and its displays correctly as a member of the organisation.

As this feels very close it would be great to complete the loop so that after a successful accept and sign up of the invitation, the user is redirected to the home page.

For more context here is my […auth].js

import { handleAuth, handleLogin } from '@auth0/nextjs-auth0';

function getSingleOrUndefined(
  item: string | string[] | undefined
): string | undefined {
  if (!item) {
    return undefined;
  const newItem = Array.isArray(item) ? item[0] : item;
  return !newItem || newItem === 'undefined' ? undefined : newItem;

export default handleAuth({
  login: (req, res, opts) => {
    return handleLogin(req, res, {
      authorizationParams: {
        invitation: getSingleOrUndefined(req.query.invitation),
        organization: getSingleOrUndefined(req.query.organization),

Here is an example of my authorise url:

In case I am missing anything? I have also attempted to join ?returnTo= to the callback url but that returned the same error.

Any advice is appreciated, thanks

By upgrading my @auth0/nextjs-auth0 npm package from 1.9.1 to 2.4.0 this error no longer returned. I did then start receiving a 404 but that was swiftly fixed by updating my callback URLs to use the redirect_uri passed in as a query parameter.

The NextJS example project for Auth0 uses an outdated package next.js/package.json at canary · vercel/next.js · GitHub I’ll raise a PR with them to avoid this in future.

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