aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joseph Garrone <[email protected]>2024-07-27 17:11:30 +0200
committerGravatar Joseph Garrone <[email protected]>2024-07-27 17:11:30 +0200
commita2d7634fe5b66885914879915dab513cf6198a4c (patch)
treec608263039562a21801c9c95838bc061fef44f5d
parentRemove kc.gen.ts (diff)
Move the entrypoint into kc.gen.tsx
-rw-r--r--src/kc.gen.tsx47
-rw-r--r--src/main.tsx30
-rw-r--r--vite.config.ts9
3 files changed, 60 insertions, 26 deletions
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<KcEnvName, string> = {};
+
+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 (
+ <Suspense fallback={fallback}>
+ {(() => {
+ switch (kcContext.themeType) {
+ case "login":
+ return <KcLoginPage kcContext={kcContext} />;
+ }
+ })()}
+ </Suspense>
+ );
+}
+
+/* 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(
<StrictMode>
- <Suspense>
- {(() => {
- switch (window.kcContext?.themeType) {
- case "login":
- return <KcLoginThemePage kcContext={window.kcContext} />;
- //case "account":
- // return <KcAccountThemePage kcContext={window.kcContext} />;
- }
- return <h1>No Keycloak Context</h1>;
- })()}
- </Suspense>
+ {!window.kcContext ? (
+ <h1>No Keycloak Context</h1>
+ ) : (
+ <KcPage kcContext={window.kcContext} />
+ )}
</StrictMode>
);
-
-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"
+ })
+ ]
});