Split kcContext among pages
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
|
||||
import { memo } from "react";
|
||||
import { kcContext } from "../kcContext";
|
||||
import { assert } from "evt/tools/typeSafety/assert";
|
||||
import { assert } from "../tools/assert";
|
||||
import type { KcPagesProperties } from "./KcProperties";
|
||||
import { Login } from "./Login";
|
||||
import { Register } from "./Register";
|
||||
|
@ -3,8 +3,8 @@ import { useState, memo } from "react";
|
||||
import { Template } from "./Template";
|
||||
import type { KcPagesProperties } from "./KcProperties";
|
||||
import { defaultKcPagesProperties } from "./KcProperties";
|
||||
import { assert } from "evt/tools/typeSafety/assert";
|
||||
import { kcContext } from "../kcContext";
|
||||
import { assert } from "../tools/assert";
|
||||
import { kcContext } from "../kcContext";
|
||||
import { useKcTranslation } from "../i18n/useKcTranslation";
|
||||
import { cx } from "tss-react";
|
||||
import { useConstCallback } from "powerhooks";
|
||||
@ -25,13 +25,16 @@ export const Login = memo((props: LoginProps) => {
|
||||
social, realm, url,
|
||||
usernameEditDisabled, login,
|
||||
auth, registrationDisabled
|
||||
}] = useState(() => (
|
||||
}] = useState(() => {
|
||||
|
||||
assert(
|
||||
kcContext !== undefined,
|
||||
"App is currently being served by keycloak"
|
||||
),
|
||||
kcContext
|
||||
));
|
||||
kcContext !== undefined &&
|
||||
kcContext.pageBasename === "login.ftl"
|
||||
);
|
||||
|
||||
return kcContext;
|
||||
|
||||
});
|
||||
|
||||
const [isLoginButtonDisabled, setIsLoginButtonDisabled] = useState(false);
|
||||
|
||||
|
@ -4,7 +4,7 @@ import { useState, memo } from "react";
|
||||
import { Template } from "./Template";
|
||||
import type { KcPagesProperties } from "./KcProperties";
|
||||
import { defaultKcPagesProperties } from "./KcProperties";
|
||||
import { assert } from "evt/tools/typeSafety/assert";
|
||||
import { assert } from "../tools/assert";
|
||||
import { kcContext } from "../kcContext";
|
||||
import { useKcTranslation } from "../i18n/useKcTranslation";
|
||||
import { cx } from "tss-react";
|
||||
@ -29,13 +29,16 @@ export const Register = memo((props: RegisterPageProps) => {
|
||||
passwordRequired,
|
||||
recaptchaRequired,
|
||||
recaptchaSiteKey
|
||||
}] = useState(() => (
|
||||
}] = useState(() => {
|
||||
|
||||
assert(
|
||||
kcContext !== undefined,
|
||||
"App is currently being served by keycloak"
|
||||
),
|
||||
kcContext
|
||||
));
|
||||
kcContext !== undefined &&
|
||||
kcContext.pageBasename === "register.ftl"
|
||||
);
|
||||
|
||||
return kcContext;
|
||||
|
||||
});
|
||||
|
||||
return (
|
||||
<Template
|
||||
|
@ -3,7 +3,7 @@ import { useState, useReducer ,useEffect, memo } from "react";
|
||||
import type { ReactNode } from "react";
|
||||
import { useKcTranslation } from "../i18n/useKcTranslation";
|
||||
import { kcContext } from "../kcContext";
|
||||
import { assert } from "evt/tools/typeSafety/assert";
|
||||
import { assert } from "../tools/assert";
|
||||
import { cx } from "tss-react";
|
||||
import { useKcLanguageTag } from "../i18n/useKcLanguageTag";
|
||||
import type { KcLanguageTag } from "../i18n/KcLanguageTag";
|
||||
|
@ -3,99 +3,126 @@ import { ftlValuesGlobalName } from "../bin/build-keycloak-theme/ftlValuesGlobal
|
||||
import type { generateFtlFilesCodeFactory } from "../bin/build-keycloak-theme/generateFtl";
|
||||
import { id } from "evt/tools/typeSafety/id";
|
||||
import type { KcLanguageTag } from "./i18n/KcLanguageTag";
|
||||
import { doExtends } from "evt/tools/typeSafety/doExtends";
|
||||
|
||||
export type KcContext = KcContext.Login | KcContext.Register;
|
||||
|
||||
export type KcContext = {
|
||||
pageBasename: Parameters<ReturnType<typeof generateFtlFilesCodeFactory>["generateFtlFilesCode"]>[0]["pageBasename"];
|
||||
url: {
|
||||
loginAction: string;
|
||||
resourcesPath: string;
|
||||
resourcesCommonPath: string;
|
||||
loginRestartFlowUrl: string;
|
||||
loginResetCredentialsUrl: string;
|
||||
registrationUrl: string;
|
||||
//Specific to register
|
||||
registrationAction: string;
|
||||
loginUrl: string;
|
||||
};
|
||||
realm: {
|
||||
displayName?: string;
|
||||
displayNameHtml?: string;
|
||||
internationalizationEnabled: boolean;
|
||||
password: boolean;
|
||||
loginWithEmailAllowed: boolean;
|
||||
registrationEmailAsUsername: boolean;
|
||||
rememberMe: boolean;
|
||||
resetPasswordAllowed: boolean;
|
||||
};
|
||||
/** Undefined if !realm.internationalizationEnabled */
|
||||
locale?: {
|
||||
supported: {
|
||||
//url: string;
|
||||
languageTag: KcLanguageTag;
|
||||
/** Is determined by languageTag. Ex: languageTag === "en" => label === "English"
|
||||
* or getLanguageLabel(languageTag) === label
|
||||
*/
|
||||
//label: LanguageLabel;
|
||||
}[];
|
||||
//NOTE: We do not expose this because the language is managed
|
||||
//client side. We use this value however to set the default.
|
||||
//current: LanguageLabel;
|
||||
},
|
||||
auth?: {
|
||||
showUsername: boolean;
|
||||
showResetCredentials: boolean;
|
||||
showTryAnotherWayLink: boolean;
|
||||
attemptedUsername?: boolean;
|
||||
selectedCredential?: string;
|
||||
};
|
||||
scripts: string[];
|
||||
message?: {
|
||||
type: "success" | "warning" | "error" | "info";
|
||||
summary: string;
|
||||
};
|
||||
isAppInitiatedAction: boolean;
|
||||
social: {
|
||||
displayInfo: boolean;
|
||||
providers?: {
|
||||
export declare namespace KcContext {
|
||||
|
||||
export type Template = {
|
||||
url: {
|
||||
loginAction: string;
|
||||
resourcesPath: string;
|
||||
resourcesCommonPath: string;
|
||||
loginRestartFlowUrl: string;
|
||||
loginUrl: string;
|
||||
alias: string;
|
||||
providerId: string;
|
||||
displayName: string;
|
||||
}[]
|
||||
};
|
||||
usernameEditDisabled: boolean;
|
||||
login: {
|
||||
username?: string;
|
||||
rememberMe: boolean;
|
||||
};
|
||||
registrationDisabled: boolean;
|
||||
//Specific to register
|
||||
messagesPerField: {
|
||||
printIfExists<T>(
|
||||
key:
|
||||
"userLabel" |
|
||||
"username" |
|
||||
"email" |
|
||||
"firstName" |
|
||||
"lastName" |
|
||||
"password" |
|
||||
"password-confirm",
|
||||
x: T
|
||||
): T | undefined;
|
||||
};
|
||||
register: {
|
||||
formData: {
|
||||
firstName?: string;
|
||||
};
|
||||
realm: {
|
||||
displayName?: string;
|
||||
lastName?: string;
|
||||
email?: string;
|
||||
username?: string;
|
||||
}
|
||||
displayNameHtml?: string;
|
||||
internationalizationEnabled: boolean;
|
||||
password: boolean;
|
||||
registrationEmailAsUsername: boolean;
|
||||
};
|
||||
/** Undefined if !realm.internationalizationEnabled */
|
||||
locale?: {
|
||||
supported: {
|
||||
//url: string;
|
||||
languageTag: KcLanguageTag;
|
||||
/** Is determined by languageTag. Ex: languageTag === "en" => label === "English"
|
||||
* or getLanguageLabel(languageTag) === label
|
||||
*/
|
||||
//label: LanguageLabel;
|
||||
}[];
|
||||
//NOTE: We do not expose this because the language is managed
|
||||
//client side. We use this value however to set the default.
|
||||
//current: LanguageLabel;
|
||||
},
|
||||
auth?: {
|
||||
showUsername: boolean;
|
||||
showResetCredentials: boolean;
|
||||
showTryAnotherWayLink: boolean;
|
||||
attemptedUsername?: boolean;
|
||||
};
|
||||
scripts: string[];
|
||||
message?: {
|
||||
type: "success" | "warning" | "error" | "info";
|
||||
summary: string;
|
||||
};
|
||||
isAppInitiatedAction: boolean;
|
||||
};
|
||||
passwordRequired: boolean;
|
||||
recaptchaRequired: boolean;
|
||||
recaptchaSiteKey: string;
|
||||
};
|
||||
|
||||
export type Login = Template & {
|
||||
pageBasename: "login.ftl";
|
||||
url: {
|
||||
loginResetCredentialsUrl: string;
|
||||
registrationUrl: string;
|
||||
};
|
||||
realm: {
|
||||
loginWithEmailAllowed: boolean;
|
||||
rememberMe: boolean;
|
||||
resetPasswordAllowed: boolean;
|
||||
};
|
||||
auth: {
|
||||
selectedCredential?: string;
|
||||
};
|
||||
registrationDisabled: boolean;
|
||||
login: {
|
||||
username?: string;
|
||||
rememberMe: boolean;
|
||||
};
|
||||
usernameEditDisabled: boolean;
|
||||
social: {
|
||||
displayInfo: boolean;
|
||||
providers?: {
|
||||
loginUrl: string;
|
||||
alias: string;
|
||||
providerId: string;
|
||||
displayName: string;
|
||||
}[]
|
||||
};
|
||||
};
|
||||
|
||||
export type Register = Template & {
|
||||
pageBasename: "register.ftl";
|
||||
url: {
|
||||
registrationAction: string;
|
||||
};
|
||||
messagesPerField: {
|
||||
printIfExists<T>(
|
||||
key:
|
||||
"userLabel" |
|
||||
"username" |
|
||||
"email" |
|
||||
"firstName" |
|
||||
"lastName" |
|
||||
"password" |
|
||||
"password-confirm",
|
||||
x: T
|
||||
): T | undefined;
|
||||
};
|
||||
register: {
|
||||
formData: {
|
||||
firstName?: string;
|
||||
displayName?: string;
|
||||
lastName?: string;
|
||||
email?: string;
|
||||
username?: string;
|
||||
}
|
||||
};
|
||||
passwordRequired: boolean;
|
||||
recaptchaRequired: boolean;
|
||||
recaptchaSiteKey: string;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
type T = KcContext["pageBasename"];
|
||||
type U = Parameters<ReturnType<typeof generateFtlFilesCodeFactory>["generateFtlFilesCode"]>[0]["pageBasename"];
|
||||
|
||||
doExtends<T, U>();
|
||||
doExtends<U, T>();
|
||||
}
|
||||
|
||||
export const kcContext = id<KcContext | undefined>((window as any)[ftlValuesGlobalName]);
|
||||
|
@ -1,125 +0,0 @@
|
||||
|
||||
import { ftlValuesGlobalName } from "../bin/build-keycloak-theme/ftlValuesGlobalName";
|
||||
import type { generateFtlFilesCodeFactory } from "../bin/build-keycloak-theme/generateFtl";
|
||||
import { id } from "evt/tools/typeSafety/id";
|
||||
import type { KcLanguageTag } from "./i18n/KcLanguageTag";
|
||||
import { doExtends } from "evt/tools/typeSafety/doExtends";
|
||||
|
||||
export type KcContext = KcContext.Login | KcContext.Register;
|
||||
|
||||
export declare namespace KcContext {
|
||||
|
||||
export type Template = {};
|
||||
|
||||
export type Login = Template & {
|
||||
pageBasename: "login.ftl";
|
||||
};
|
||||
|
||||
export type Register = Template & {
|
||||
pageBasename: "register.ftl";
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
type T = KcContext["pageBasename"];
|
||||
type U = Parameters<ReturnType<typeof generateFtlFilesCodeFactory>["generateFtlFilesCode"]>[0]["pageBasename"];
|
||||
|
||||
doExtends<T, U>();
|
||||
doExtends<U, T>();
|
||||
|
||||
}
|
||||
|
||||
|
||||
export type KcContext = {
|
||||
pageBasename: Parameters<ReturnType<typeof generateFtlFilesCodeFactory>["generateFtlFilesCode"]>[0]["pageBasename"];
|
||||
url: {
|
||||
loginAction: string;
|
||||
resourcesPath: string;
|
||||
resourcesCommonPath: string;
|
||||
loginRestartFlowUrl: string;
|
||||
loginResetCredentialsUrl: string;
|
||||
registrationUrl: string;
|
||||
registrationAction: string;
|
||||
loginUrl: string;
|
||||
};
|
||||
realm: {
|
||||
displayName?: string;
|
||||
displayNameHtml?: string;
|
||||
internationalizationEnabled: boolean;
|
||||
password: boolean;
|
||||
loginWithEmailAllowed: boolean;
|
||||
registrationEmailAsUsername: boolean;
|
||||
rememberMe: boolean;
|
||||
resetPasswordAllowed: boolean;
|
||||
};
|
||||
/** Undefined if !realm.internationalizationEnabled */
|
||||
locale?: {
|
||||
supported: {
|
||||
//url: string;
|
||||
languageTag: KcLanguageTag;
|
||||
/** Is determined by languageTag. Ex: languageTag === "en" => label === "English"
|
||||
* or getLanguageLabel(languageTag) === label
|
||||
*/
|
||||
//label: LanguageLabel;
|
||||
}[];
|
||||
//NOTE: We do not expose this because the language is managed
|
||||
//client side. We use this value however to set the default.
|
||||
//current: LanguageLabel;
|
||||
},
|
||||
auth?: {
|
||||
showUsername: boolean;
|
||||
showResetCredentials: boolean;
|
||||
showTryAnotherWayLink: boolean;
|
||||
attemptedUsername?: boolean;
|
||||
selectedCredential?: string;
|
||||
};
|
||||
scripts: string[];
|
||||
message?: {
|
||||
type: "success" | "warning" | "error" | "info";
|
||||
summary: string;
|
||||
};
|
||||
isAppInitiatedAction: boolean;
|
||||
social: {
|
||||
displayInfo: boolean;
|
||||
providers?: {
|
||||
loginUrl: string;
|
||||
alias: string;
|
||||
providerId: string;
|
||||
displayName: string;
|
||||
}[]
|
||||
};
|
||||
usernameEditDisabled: boolean;
|
||||
login: {
|
||||
username?: string;
|
||||
rememberMe: boolean;
|
||||
};
|
||||
registrationDisabled: boolean;
|
||||
messagesPerField: {
|
||||
printIfExists<T>(
|
||||
key:
|
||||
"userLabel" |
|
||||
"username" |
|
||||
"email" |
|
||||
"firstName" |
|
||||
"lastName" |
|
||||
"password" |
|
||||
"password-confirm",
|
||||
x: T
|
||||
): T | undefined;
|
||||
};
|
||||
register: {
|
||||
formData: {
|
||||
firstName?: string;
|
||||
displayName?: string;
|
||||
lastName?: string;
|
||||
email?: string;
|
||||
username?: string;
|
||||
}
|
||||
};
|
||||
passwordRequired: boolean;
|
||||
recaptchaRequired: boolean;
|
||||
recaptchaSiteKey: string;
|
||||
};
|
||||
|
||||
export const kcContext = id<KcContext | undefined>((window as any)[ftlValuesGlobalName]);
|
2
src/lib/tools/assert.ts
Normal file
2
src/lib/tools/assert.ts
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
export { assert } from "evt/tools/typeSafety/assert";
|
Reference in New Issue
Block a user