Ouverture de l'authentification dans une modal

This commit is contained in:
2026-04-13 23:09:17 +02:00
parent 7080fa8450
commit 740074c49e
6 changed files with 209 additions and 6 deletions

View File

@@ -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();
})();