From a2d7634fe5b66885914879915dab513cf6198a4c Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sat, 27 Jul 2024 17:11:30 +0200 Subject: [PATCH] Move the entrypoint into kc.gen.tsx --- src/kc.gen.tsx | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/main.tsx | 30 +++++++----------------------- vite.config.ts | 9 ++++++--- 3 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 src/kc.gen.tsx diff --git a/src/kc.gen.tsx b/src/kc.gen.tsx new file mode 100644 index 0000000..b9240c3 --- /dev/null +++ b/src/kc.gen.tsx @@ -0,0 +1,47 @@ +/* prettier-ignore-start */ + +/* eslint-disable */ + +// @ts-nocheck + +// noinspection JSUnusedGlobalSymbols + +// This file is auto-generated by Keycloakify + +import { lazy, Suspense, type ReactNode } from "react"; + +export type ThemeName = "keycloakify-starter"; + +export const themeNames: ThemeName[] = ["keycloakify-starter"]; + +export type KcEnvName = never; + +export const kcEnvNames: KcEnvName[] = []; + +export const kcEnvDefaults: Record = {}; + +type KcContext = import("./login/KcContext").KcContext; + +declare global { + interface Window { + kcContext?: KcContext; + } +} + +export const KcLoginPage = lazy(() => import("./login/KcPage")); + +export function KcPage(props: { kcContext: KcContext; fallback?: ReactNode }) { + const { kcContext, fallback } = props; + return ( + + {(() => { + switch (kcContext.themeType) { + case "login": + return ; + } + })()} + + ); +} + +/* prettier-ignore-end */ diff --git a/src/main.tsx b/src/main.tsx index 61406d2..2e7e36e 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,6 +1,7 @@ /* eslint-disable react-refresh/only-export-components */ import { createRoot } from "react-dom/client"; -import { StrictMode, lazy, Suspense } from "react"; +import { StrictMode } from "react"; +import { KcPage } from "./kc.gen"; // The following block can be uncommented to test a specific page with `yarn dev` // Don't forget to comment back or your bundle size will increase @@ -15,29 +16,12 @@ if (import.meta.env.DEV) { } */ -const KcLoginThemePage = lazy(() => import("./login/KcPage")); -//const KcAccountThemePage = lazy(() => import("./account/KcPage")); - createRoot(document.getElementById("root")!).render( - - {(() => { - switch (window.kcContext?.themeType) { - case "login": - return ; - //case "account": - // return ; - } - return

No Keycloak Context

; - })()} -
+ {!window.kcContext ? ( +

No Keycloak Context

+ ) : ( + + )}
); - -declare global { - interface Window { - kcContext?: - | import("./login/KcContext").KcContext - //| import("./account/KcContext").KcContext; - } -} diff --git a/vite.config.ts b/vite.config.ts index cb8365c..752e777 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,7 +4,10 @@ import { keycloakify } from "keycloakify/vite-plugin"; // https://vitejs.dev/config/ export default defineConfig({ - plugins: [react(), keycloakify({ - accountThemeImplementation: "none" - })] + plugins: [ + react(), + keycloakify({ + accountThemeImplementation: "none" + }) + ] });