Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.7 kB
2
Indexable
Never
document.addEventListener('DOMContentLoaded', function() {
    const urlParams = new URLSearchParams(window.location.search);
    const redirectUri = urlParams.get('redirect_uri');
    const cleanRedirectUri = (typeof DOMPurify === 'function') ? DOMPurify.sanitize(redirectUri) : null;
    const backBtn = document.getElementById('back-btn');
    const trigger = document.getElementById('tech-details-trigger');
    const clientId = getClientId();
    const oktaLanguage = getCookie('okta_user_lang');
    let language = 'en';
    let setConfig;

    // Set the config to use.
    if (loginConfig?.merchants?.indexOf(clientId) > -1) { // Merchant
      setConfig = 'merchantConfig';
    }
    else if (clientId && loginConfig) { // Customer
      setConfig = 'customerConfig';
    }

    // Set the language in use.  If not set in Okta or the browser, use English.
    language = oktaLanguage ? oktaLanguage : navigator.languages[0].split('-')[0];
    if (!loginConfig?.[setConfig]?.[language]) { language = 'en'; }

    // Set the help link on the login page.
    document.getElementById('help-link').setAttribute('href', loginConfig?.[setConfig]?.[language].helpLink);

    // Set the text and link for the Back button.
    if (cleanRedirectUri && backBtn) {
      backBtn.innerText = 'Go to Login Page';
      backBtn.setAttribute('href', cleanRedirectUri);
    }

    // Toggle open and closed the Technical Details section on click.
    if (trigger) {
      trigger.addEventListener('click', e => {
        trigger.classList.toggle('open');
        document.getElementById('tech-details-section').classList.toggle('open');
      }, false);
    }
});
Leave a Comment