From 28990a12da4d197c072f31a9097f6d13e4523aef Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Mon, 9 Sep 2024 07:39:14 +0200 Subject: [PATCH] Fix LoginRecoveryAuthnCodeConfig --- ...skeysConditionalAuthenticate.useScript.tsx | 13 +- .../pages/LoginRecoveryAuthnCodeConfig.tsx | 130 +--------------- ...LoginRecoveryAuthnCodeConfig.useScript.tsx | 142 ++++++++++++++++++ src/tools/useInsertScriptTags.ts | 16 +- 4 files changed, 168 insertions(+), 133 deletions(-) create mode 100644 src/login/pages/LoginRecoveryAuthnCodeConfig.useScript.tsx diff --git a/src/login/pages/LoginPasskeysConditionalAuthenticate.useScript.tsx b/src/login/pages/LoginPasskeysConditionalAuthenticate.useScript.tsx index 15b4b957..ceb7aa52 100644 --- a/src/login/pages/LoginPasskeysConditionalAuthenticate.useScript.tsx +++ b/src/login/pages/LoginPasskeysConditionalAuthenticate.useScript.tsx @@ -19,6 +19,7 @@ assert string; + isFetchingTranslations: boolean; }; export function useScript(params: { authButtonId: string; kcContext: KcContextLike; i18n: I18nLike }) { @@ -26,18 +27,18 @@ export function useScript(params: { authButtonId: string; kcContext: KcContextLi const { url, isUserIdentified, challenge, userVerification, rpId, createTimeout } = kcContext; - const { msgStr } = i18n; + const { msgStr, isFetchingTranslations } = i18n; const { insertScriptTags } = useInsertScriptTags({ componentOrHookName: "LoginRecoveryAuthnCodeConfig", scriptTags: [ { type: "module", - textContent: ` + textContent: () => ` import { authenticateByWebAuthn } from "${url.resourcesPath}/js/webauthnAuthenticate.js"; import { initAuthenticate } from "${url.resourcesPath}/js/passkeysConditionalAuth.js"; - const authButton = document.getElementById(${JSON.stringify(authButtonId)}); + const authButton = document.getElementById("${authButtonId}"); const input = { isUserIdentified : ${isUserIdentified}, challenge : '${challenge}', @@ -62,6 +63,10 @@ export function useScript(params: { authButtonId: string; kcContext: KcContextLi }); useEffect(() => { + if (isFetchingTranslations) { + return; + } + insertScriptTags(); - }, []); + }, [isFetchingTranslations]); } diff --git a/src/login/pages/LoginRecoveryAuthnCodeConfig.tsx b/src/login/pages/LoginRecoveryAuthnCodeConfig.tsx index 2eed0465..d56f934f 100644 --- a/src/login/pages/LoginRecoveryAuthnCodeConfig.tsx +++ b/src/login/pages/LoginRecoveryAuthnCodeConfig.tsx @@ -1,7 +1,6 @@ -import { useEffect } from "react"; import { clsx } from "keycloakify/tools/clsx"; import { getKcClsx, type KcClsx } from "keycloakify/login/lib/kcClsx"; -import { useInsertScriptTags } from "keycloakify/tools/useInsertScriptTags"; +import { useScript } from "keycloakify/login/pages/LoginRecoveryAuthnCodeConfig.useScript"; import type { PageProps } from "keycloakify/login/pages/PageProps"; import type { KcContext } from "../KcContext"; import type { I18n } from "../i18n"; @@ -18,130 +17,9 @@ export default function LoginRecoveryAuthnCodeConfig(props: PageProps" + - "kc-download-recovery-codes" + - "

${msgStr("recovery-codes-download-file-header")}

" + - "
" + recoveryCodeListHTML + "
" + - "

${msgStr("recovery-codes-download-file-description")}

" + - "

${msgStr("recovery-codes-download-file-date")} " + formatCurrentDateTime() + "

" + - ""; - } - - function printRecoveryCodes() { - var w = window.open(); - w.document.write(buildPrintContent()); - w.print(); - w.close(); - } - - var printButton = document.getElementById("printRecoveryCodes"); - printButton && printButton.addEventListener("click", printRecoveryCodes); - ` - } - ] - }); - - useEffect(() => { - insertScriptTags(); - }, []); + useScript({ olRecoveryCodesListId, i18n }); return (