/** * Ecwid Custom JavaScript for SSO Integration * ============================================= * * PASTE THIS CODE into Ecwid Admin → Design → Custom JavaScript * URL: https://my.ecwid.com/cp/#design-customjs * * This script enables automatic SSO (Single Sign-On) for the Alia Nature shop. * When a user is logged in via auth.alianature.shop, they will be automatically * logged into the Ecwid storefront as well. * * How it works: * 1. Sets window.ecwid_sso_profile = "" to enable Ecwid SSO mode (MUST happen before Ecwid loads) * 2. Fetches the signed SSO profile from auth.alianature.shop * 3. Updates Ecwid with the real user profile via Ecwid.setSsoProfile() */ // Step 1: Enable SSO mode BEFORE Ecwid initializes // This MUST be set before Ecwid's ecommerce script runs window.ecwid_sso_profile = ""; // Step 2: Fetch real SSO profile from auth server and update Ecwid (function () { function loadSsoProfile() { fetch("https://auth.alianature.shop/api/ecwid/sso-profile", { credentials: "include", }) .then(function (r) { return r.json(); }) .then(function (data) { if (data.success && data.ssoProfile) { window.ecwid_sso_profile = data.ssoProfile; if ( typeof Ecwid !== "undefined" && typeof Ecwid.setSsoProfile === "function" ) { Ecwid.setSsoProfile(data.ssoProfile); } } }) .catch(function (err) { console.log("[Alia SSO] Profile fetch failed:", err); }); } // If Ecwid API is already loaded, fetch profile immediately if (typeof Ecwid !== "undefined" && typeof Ecwid.OnAPILoaded !== "undefined") { Ecwid.OnAPILoaded.add(loadSsoProfile); } // Also try immediately in case Ecwid is already loaded loadSsoProfile(); })();