This is the documentation for v9, checkout the latest version
Keycloakify
HomeGitHubStartersStorybookDiscordKeycloak-js Alternative
v9
  • Keycloakify
  • Release Notes & Upgrade Instructions
  • FAQ
v9
  • πŸ‘¨β€πŸ’»Quick start
  • πŸ“₯Importing your theme in Keycloak
  • πŸ”©Keycloakify in my App
  • πŸ–ΌοΈImporting assets and fonts
  • πŸ“§Email customization
  • βœ’οΈTerms and conditions
  • βœ…Realtime input validation and custom registration fields
  • ⚠️Limitations
  • πŸ”§Environment Variables
  • 🌎i18n: msg(...)
  • πŸ“–Build options
  • πŸ’‚Email domain acceptlist
  • πŸ›‘Keycloak error in log
  • πŸŒ‰Passing values from the App to the theme
  • πŸ’ŸContributing
  • πŸ€”How it works
  • ⬆️Migration guides
    • ⬆️CRA -> Vite
    • ⬆️v8 -> v9
    • ⬆️v7 -> v8
    • ⬆️v6 -> v7
    • ⬆️v6.x -> v6.12
    • ⬆️v5 -> v6
Powered by GitBook
On this page

Was this helpful?

Terms and conditions

Consent page

PreviousEmail customizationNextRealtime input validation and custom registration fields

Last updated 27 days ago

Was this helpful?

Many organizations have a requirement that when a new user logs in for the first time, they need to agree to the terms and conditions of the website.

First you need to enable the required action on the Keycloak server admin console:\

Then you load your own terms in Markdown format like this:

login/KcApp.tsx
import { lazy, Suspense } from "react";
import Fallback, { type PageProps } from "keycloakify/login";
import type { KcContext } from "./kcContext";
import { useI18n } from "./i18n";
import { useDownloadTerms }Β from "keycloakify/login";
import tos_en_url from "./assets/tos_en.md";
import tos_fr_url from "./assets/tos_fr.md";

const DefaultTemplate = lazy(() => import("keycloakify/login/Template"));

export default function App(props: { kcContext: KcContext; }) {

    const { kcContext } = props;

    const i18n = useI18n({ kcContext });
    
    useDownloadTerms({
	kcContext,
	"downloadTermMarkdown": async ({ currentLanguageTag }) => {

            const tos_url = (() => {
                switch (currentLanguageTag) {
                    case "fr": return tos_fr_url;
                    default: return tos_en_url;
                }
            })();


            if ("__STORYBOOK_ADDONS" in window) {
                // NOTE: In storybook, when you import a .md file you get the content of the file.
                // In Create React App on the other hand you get an url to the file.
                return tos_url;
            }

            const markdownString = await fetch(tos_url).then(response => response.text());

            return markdownString;
	}
    });

    if (i18n === null) {
        //NOTE: Locales not yet downloaded, we could as well display a loading progress but it's usually a matter of milliseconds.
        return null;
    }

    return (
        <Suspense>
            {(() => {
                switch (kcContext.pageId) {
                    default: return <Fallback {...{ kcContext, i18n }} Template={DefaultTemplate} doUseDefaultCss />;      
                }
            })()}
        </Suspense>
    );

}

You can also eject the terms.ftl page if you're not happy with the default look:

Nice to know: You can access user infos and attribute in the Terms page. This enables you to display different terms depending on what option the user selected on the registration page:

βœ’οΈ
keycloakify-starter/Login.tsx at main Β· codegouvfr/keycloakify-starterGitHub
Cloud IAM - Keycloak Identity and Access Management as a Service
Feeling overwhelmed? Check out our exclusive sponsor's Cloud-IAM consulting services to simplify your experience.
Logo
Logo