From 1131d4e0263b07bc21827d29bc556f7be1282ae7 Mon Sep 17 00:00:00 2001 From: boshi1 Date: Tue, 14 Feb 2023 13:38:07 +0300 Subject: [PATCH] innerHtml --- src/index.ts | 64 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/src/index.ts b/src/index.ts index 554ce3e..6270273 100644 --- a/src/index.ts +++ b/src/index.ts @@ -127,8 +127,8 @@ interface DebugSettings { interface SDKConfig { clientSdkApiKey: string; webauthnClientId: string; - registerRedirectUrl: string; - authenticationRedirectUrl: string; + registerRedirectUrl?: string; + authenticationRedirectUrl?: string; getNonce?: () => string; debug?: DebugSettings; } @@ -207,8 +207,8 @@ class SDK { constructor({ clientSdkApiKey = "", webauthnClientId = "", - registerRedirectUrl = "", - authenticationRedirectUrl = "", + registerRedirectUrl, + authenticationRedirectUrl, getNonce, debug = { url: "https://auth.autharmor.dev" } }: SDKConfig) { @@ -470,7 +470,10 @@ class SDK { if (type === "success") { if (loadingText) { - loadingText.innerHTML = `Authenticated!
Please wait...`; + loadingText.insertAdjacentHTML( + "beforeend", + `Authenticated!
Please wait...` + ); } return; @@ -583,7 +586,9 @@ class SDK { }; private init = () => { - document.body.innerHTML += ` + document.body?.insertAdjacentHTML( + "beforeend", + `
@@ -604,8 +609,8 @@ class SDK { class="${styles.autharmorIcon}" />
+ isMobile() ? styles.qrCodeMobile : "" + }"> ${ isMobile() ? ` @@ -656,7 +661,8 @@ class SDK { }
- `; + ` + ); const showPopupQrBtn = $(`.${styles.showPopupQrcodeBtn}`); const hidePopupQrBtn = $(`.${styles.hidePopupQrcodeBtn}`); @@ -918,7 +924,7 @@ class SDK { const [, keyPayloadBase64] = this.publicKey?.split(".") ?? []; const keyPayload = JSON.parse(atob(keyPayloadBase64)); const requestPath = urlParser.pathname.replace(/\/$/gi, ""); - const host = location.hostname; + const host = window.location.hostname; const signature = [keyPayload.key, timestamp, requestPath, host].join("|"); const { hashBuffer: signatureBuffer } = await this.sha256(signature); @@ -1228,7 +1234,7 @@ class SDK { ? "Please click the button above to start registration" : "Please scan the QR Code with your phone" ); - this.showPopupQRCode(false); + this.showPopupQRCode(true); this.getEnrollmentStatus({ id: body.user_id, @@ -1908,7 +1914,9 @@ class SDK { parsedOptions.methods?.includes("authenticator")) && parsedOptions.usernameless !== false; - element.innerHTML = ` + element.insertAdjacentHTML( + "beforeend", + `
@@ -1930,18 +1938,18 @@ class SDK {

An error has occurred while communicating with the AuthArmor API, please make sure you've added the following domain to the allowed - domains list: "${location.host}" + domains list: "${window.location.host}"

+ parsedOptions.defaultTab === "login" ? styles.activeTab : "" + }" data-tab="login"> ${this.i18n?.auth?.tabName}
${this.i18n?.register?.tabName}
+ parsedOptions.defaultTab === "register" ? styles.activeTab : "" + }" data-tab="register">${this.i18n?.register?.tabName}

${this.i18n?.auth?.action}

@@ -2020,10 +2028,10 @@ class SDK { id="register" class="${styles.tabContent}" style="${!authenticatorEnabled ? "min-height: 164px;" : ""} ${ - parsedOptions.defaultTab === "register" - ? "display: block;" - : "display: none;" - }"> + parsedOptions.defaultTab === "register" + ? "display: block;" + : "display: none;" + }">

${this.i18n?.register?.usernameLabel} @@ -2045,9 +2053,12 @@ class SDK {

- `; + ` + ); - document.body.innerHTML += ` + element.insertAdjacentHTML( + "beforeend", + `
@@ -2105,7 +2116,8 @@ class SDK {

Choose another method

- `; + ` + ); this.textIndex += 1;