Similar question here
I'm creating two react apps, one on port 3000 and the other one on port 3001, both in localhost. The project on localhost:3000 is an signin api, similar to google oauth. The app on localhost:3001 needs to open an popup to allow user to login on localhost:3000 and finally return the user account to localhost:3001.
localhost:3001 relevant code:
let browser = window.self;
browser.onSuccess = function (res) {
// Do something
}
browser.open("http://localhost:3000/singin", "Sign in", opts);
localhost:3000 relevant code:
// Set document domain to same domain of window.opener
document.domain = "localhost:3001";
// Call onSuccess function
window.opener.onSuccess(user);
The function exists, but when its called it throws the following error: SecurityError: Permission denied to access property "onSuccess" on cross-origin object.
Belive it or not, yesterday it was working just fine after set document.domain equals to localhost:3001.
What I tried:
- Add this header on index.html of localhost:3000:
<meta http-equiv="Access-Control-Allow-Origin" content="localhost:3001/">
- Add a protocol (like "http://") to "document.domain".
- Allow firewall access to both ports (I was desperate ok?)
Edit
Code for localhost:3001 here. Files in src/localhost3000 are from localhost:3001 project.
Please
I DON'T want to use postMessage.