summaryrefslogtreecommitdiff
path: root/inject/disable-password-login.js
blob: 432dc8194c7c012c11e92ed96a339c574cbde242 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export function disablePasswordLogin() {
  const queryString = new URLSearchParams(window.location.search);
  if (queryString.get("pwauth") == null) {
    document.addEventListener("DOMContentLoaded", function () {
      if (document.querySelector(".alert") || queryString.get("oauth_error")) {
        console.warn("Not redirecting to SSO due to error");
        return;
      }

      const sso = document.querySelector(".o_auth_oauth_providers");
      if (sso) {
        const link = sso.getElementsByTagName("a")[0];
        if (link.innerText.search("Authentik") + link.innerText.search("TONI SSO") > 0) {
          console.info("Redirecting to SSO login:", link.href);
          window.location.replace(link.href);
        }
      }
    });
  }
  else {
    console.info("Not redirecting to SSO due to pwauth query string");
  }
}