Я попробовал ниже:
в родительском окне:
Код: Выделить всё
const width = 600;
const height = 700;
const left = window.screenX + (window.outerWidth - width) / 2;
const top = window.screenY + (window.outerHeight - height) / 2;
const url = `${window.location.origin}/auth-onedrive`;
const authWindow = window.open(
url,
"OneDrive Login",
`width=${width},height=${height},left=${left},top=${top}`
);
if (!authWindow) {
console.warn("Popup blocked");
retryLogin();
return;
}
const handleMessage = (event) => {
// Make sure it’s from our origin
if (event.data?.type === "onedrive-auth-result") {
console.log("Received message from popup:", event.data.status);
window.removeEventListener("message", handleMessage);
retryLogin();
}
};
window.addEventListener("message", handleMessage);
Код: Выделить всё
dispatchRedux(oneDriveLogin(payload, "Authenticating with OneDrive..."))
.then(handleResponse)
.catch(handleError);
const notifyParent = (status) => {
if (window.opener) {
window.opener.postMessage(
{ type: "onedrive-auth-result", status }
);
}
};
const handleResponse = (res) => {
if (res?.status === 'success' && res?.data?.loggedIn) {
setLoginStatus("Login Successful.");
notifyParent("success");
window.close();
} else if (res?.status === 'success' && !res?.data?.loggedIn) {
setLoginStatus("Redirecting...");
window.location.href = res?.data?.redirectUrl;
}
};
Подробнее здесь: https://stackoverflow.com/questions/798 ... -is-closed
Мобильная версия