Ouverture de l'authentification dans une modal
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
const assetTokenStorageKey = "chesscubing-arena-asset-token";
|
||||
let viewportStarted = false;
|
||||
let audioContext = null;
|
||||
let authModalMessageHandler = null;
|
||||
|
||||
function syncViewportHeight() {
|
||||
const visibleHeight = window.visualViewport?.height ?? window.innerHeight;
|
||||
@@ -198,5 +199,51 @@
|
||||
},
|
||||
};
|
||||
|
||||
window.chesscubingAuthModal = {
|
||||
registerListener(dotNetReference) {
|
||||
if (authModalMessageHandler) {
|
||||
window.removeEventListener("message", authModalMessageHandler);
|
||||
}
|
||||
|
||||
authModalMessageHandler = (event) => {
|
||||
if (event.origin !== window.location.origin) {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = event.data;
|
||||
if (!data || data.source !== "chesscubing-auth-modal" || typeof data.status !== "string") {
|
||||
return;
|
||||
}
|
||||
|
||||
dotNetReference.invokeMethodAsync("HandleAuthModalMessage", data.status).catch(() => undefined);
|
||||
};
|
||||
|
||||
window.addEventListener("message", authModalMessageHandler);
|
||||
},
|
||||
|
||||
unregisterListener() {
|
||||
if (!authModalMessageHandler) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.removeEventListener("message", authModalMessageHandler);
|
||||
authModalMessageHandler = null;
|
||||
},
|
||||
|
||||
notifyParent(status) {
|
||||
if (!window.parent || window.parent === window) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
source: "chesscubing-auth-modal",
|
||||
status,
|
||||
},
|
||||
window.location.origin,
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
startViewport();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user