AuthSdkError: Unable to retrieve OAuth redirect params cookie while using org to org idp discovery

Hi

I have a React SPA and I am using the Okta widget to authenticate. When I am trying to authenticate a org to org user using idpDiscovery set to true, I get redirected to the following url coming up with error ‘AuthSdkError: Unable to retrieve OAuth redirect params cookie’

http://demourl.com/implicit/callback#id_token={tokenvalue}&access_token={tokenvalue}&token_type=Bearer&expires_in=3600&scope=openid+profile&state=xyz

Here’s the code for my onSuccess function:

    onSuccess = res => {
                if (res.status === 'SUCCESS') {
                    return this.props.auth.redirect({
                        sessionToken: res.session.token
                    });
                } else if  res.status === 'IDP_DISCOVERY' {
                    var username = document.getElementById("idp-discovery-username").value;
                    var xhttp = new XMLHttpRequest();
                    var orgUrl = "process.env.REACT_APP_OKTA_ORG_URL";
                    var webFingerUrl = orgUrl + ".well-known/webfinger?resource=" + encodeURIComponent("okta:acct:" + username);
                    var params = {
                        "oauth": "oauth2/default/v1/authorize",
                        "clientId": process.env.REACT_APP_OKTA_CLIENT_ID,
                        "scopes": ["openid", "profile"],
                        "responseMode": "fragment",
                        "responseType": ["token", "id_token"],
                        "redirectUri": process.env.REACT_APP_PROD_URL + '/implicit/callback',
                        "state": "xyz", // enter random char generator here.
                        "nonce": "xyz" // same as above.
                    };
                    var finalRedirectUrl = orgUrl + params["oauth"] + "?client_id=" + params["clientId"] + "&scope=" + params["scopes"][0] + " " + params["scopes"][1] + "&response_mode=" + params["responseMode"] + "&response_type=" + params["responseType"][0] + " " + params["responseType"][1] + "&redirect_uri=" + params["redirectUri"] + "&state=" + params["state"] + "&nonce=" + params["nonce"];
                    xhttp.open("GET", webFingerUrl, true);
                    xhttp.responseType = "json";
                    xhttp.send();
                    xhttp.onload = function () {
                        var response = xhttp.response;
                        var link = response.links[0].href;
                        console.log(link);

                        var idp = link.slice(0, (link.length - 1)); // slicing is required to remove the '#' from the end of the idp link.
                        console.log(idp);
                        window.location.href = idp + "&fromURI=" + encodeURIComponent(finalRedirectUrl);
                        console.log(window.location.href);
                    }
                }

            };

Any suggestions as to what to do next?