Reputation: 7692
I have an Angular app which uses a websocket connection to interact with a server. Now I need to implement OAuth in third party service, however I cannot handle any events on new tab opened via window.open(url)
.
The OAuth API redirects the window to my domain and returns token in URL query params. I need to catch this token to work with this. How can this be implemented?
const eHealthWind = window.open(msg.data.url);
console.log(eHealthWind.window);
eHealthWind.onload = function () {
eHealthWind.onpopstate = function (e) {
console.log('pop', e);
};
};
Upvotes: 0
Views: 113
Reputation: 6269
This would be a possible way:
const loggedInPromise = new Promise((res) => {
const eHealthWind = window.open(msg.data.url);
const intervalId = setInterval(function() {
try {
res(eHealthWind.location.href);
clearInterval(intervalId);
eHealthWind.close();
} catch (error) {
}
}, 1000);
})
loggedInPromise.then((urlWithToken) => { console.log(urlWithToken); })
Upvotes: 1