Wix OAuth installer redirect to "undefined" instead of my redirect URL

Why does my Wix OAuth installer redirect to “undefined” instead of my redirect URL?

I’m building an external application, that needs access to the contacts from a Wix site. To do so, I must obtain an access token and refresh token to use the Wix Contacts REST API.

Following the custom-authentication-legacy documentation, I created an app in the Wix Developer Console. I configured both the AppUrl and the RedirectURL to be my external app domain, and I obtained the appId and appSecret.

In my external application, I implemented the OAuth flow as follows:

Step 1: When a user clicks on “Activate Wix,” my external app redirects them to https://www.wix.com/installer/install with the following query parameters:

appId (set to my Wix app ID)
state (some state token, e.g., our internal id_token)
redirectUrl (set to my external app domain)

On Wix’s side, the user is then prompted to choose a Wix site to install the app and to accept the permissions.

Step 2: According to the docs, after the user consents, they should be redirected back to my external domain with a query param: code=<AUTH_CODE>.

However, instead of that, I’m getting redirected to a URL like: https://www.wix.com/installer/undefined which results in a 404 error.

I’ve verified that the parameters I send match the documentation. My expectation is that after a successful installation, Wix would redirect to my provided redirectUrl with an authorization code. Instead, I get a redirect to “undefined.”

Questions:

What could be causing Wix to generate a URL with “undefined” in place of the expected redirect URL? Is there any additional parameter or configuration needed on the Wix Developer Console for this flow to work correctly? Are there known issues with the custom-authentication-legacy flow that might lead to this behavior? Any help or guidance to debug this OAuth flow would be appreciated!