Fix MSAL.js load order: use onload callback

Define initMsal() first, then load CDN script with onload="initMsal()".
Prevents 'msal is not defined' race condition.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
SamoilenkoVadym 2026-02-09 21:45:29 +00:00
parent ff3b89f18c
commit eaa12be728

View file

@ -301,13 +301,16 @@
</div>
{% if sso_enabled %}
<script src="https://alcdn.msauth.net/browser/2.38.3/js/msal-browser.min.js"></script>
<script>
let msalInstance = null;
let msalReady = false;
// Initialize MSAL asynchronously after script loads
(async function initMsal() {
// Called after MSAL.js CDN script loads
async function initMsal() {
if (typeof msal === 'undefined') {
console.error("MSAL library not loaded");
return;
}
try {
const msalConfig = {
auth: {
@ -326,7 +329,7 @@
} catch (err) {
console.error("MSAL init failed:", err);
}
})();
}
async function loginWithMicrosoft() {
const btn = document.getElementById('ssoBtn');
@ -373,6 +376,7 @@
}
}
</script>
<script src="https://alcdn.msauth.net/browser/2.38.3/js/msal-browser.min.js" onload="initMsal()" onerror="console.error('Failed to load MSAL.js from CDN')"></script>
{% endif %}
</body>
</html>