import { assert } from "keycloakify/tools/assert"; import { clsx } from "keycloakify/tools/clsx"; import { usePrepareTemplate } from "keycloakify/lib/usePrepareTemplate"; import { type TemplateProps } from "keycloakify/login/TemplateProps"; import { useGetClassName } from "keycloakify/login/lib/useGetClassName"; import type { KcContext } from "./kcContext"; import type { I18n } from "./i18n"; export default function Template(props: TemplateProps) { const { displayInfo = false, displayMessage = true, displayRequiredFields = false, headerNode, showUsernameNode = null, socialProvidersNode = null, infoNode = null, kcContext, i18n, doUseDefaultCss, classes, children } = props; const { getClassName } = useGetClassName({ doUseDefaultCss, classes }); const { msg, msgStr, changeLocale, labelBySupportedLanguageTag, currentLanguageTag } = i18n; const { realm, locale, auth, url, message, isAppInitiatedAction, authenticationSession, scripts } = kcContext; const { isReady } = usePrepareTemplate({ "styles": !doUseDefaultCss ? [] : [ `${url.resourcesCommonPath}/node_modules/@patternfly/patternfly/patternfly.min.css`, `${url.resourcesCommonPath}/node_modules/patternfly/dist/css/patternfly.min.css`, `${url.resourcesCommonPath}/node_modules/patternfly/dist/css/patternfly-additions.min.css`, `${url.resourcesCommonPath}/lib/pficon/pficon.css`, `${url.resourcesPath}/css/login.css` ], "scripts": [ { "isModule": true, "source": { "type": "url", "src": `${url.resourcesPath}/js/menu-button-links.js` } }, ...(authenticationSession === undefined ? [] : [ { "isModule": true, "source": { "type": "inline" as const, "code": [ `import { checkCookiesAndSetTimer } from "${url.resourcesPath}/js/authChecker.js";`, ``, `checkCookiesAndSetTimer(`, ` "${authenticationSession.authSessionId}",`, ` "${authenticationSession.tabId}",`, ` "${url.ssoLoginInOtherTabsUrl}"`, `);` ].join("\n") } } ]), ...scripts.map( script => ({ "isModule": false, "source": { "type": "url", "src": script } } as const) ) ], "htmlClassName": getClassName("kcHtmlClass"), "bodyClassName": getClassName("kcBodyClass"), "htmlLangProperty": locale?.currentLanguageTag, "documentTitle": msgStr("loginTitle", kcContext.realm.displayName) }); if (!isReady) { return null; } return (
{msg("loginTitleHtml", realm.displayNameHtml)}
{realm.internationalizationEnabled && (assert(locale !== undefined), true) && locale.supported.length > 1 && (
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} {labelBySupportedLanguageTag[currentLanguageTag]}
)} {!(auth !== undefined && auth.showUsername && !auth.showResetCredentials) ? ( displayRequiredFields ? (
* {msg("requiredFields")}

{headerNode}

) : (

{headerNode}

) ) : displayRequiredFields ? (
* {msg("requiredFields")}
{showUsernameNode}
{msg("restartLoginTooltip")}
) : ( <> {showUsernameNode}
{msg("restartLoginTooltip")}
)}
{/* App-initiated actions should not see warning messages about the need to complete the action during login. */} {displayMessage && message !== undefined && (message.type !== "warning" || !isAppInitiatedAction) && (
{message.type === "success" && } {message.type === "warning" && } {message.type === "error" && } {message.type === "info" && }
)} {children} {auth !== undefined && auth.showTryAnotherWayLink && (
)} {socialProvidersNode} {displayInfo && (
{infoNode}
)}
); }