Keycloakify
HomeGitHubStorybookStarter TemplateAlternative to keycloak-js
v10
  • Documentation
  • Release Notes & Upgrade Instructions
  • FAQ
v10
  • ๐Ÿ‘จโ€๐Ÿ’ปQuick start
  • ๐ŸงชTesting your Theme
    • In Storybook
    • In a Keycloak Docker Container
    • With Vite or Webpack in dev mode
  • ๐Ÿ”ฉIntegrating Keycloakify in your Codebase
    • In your React Project
      • In your Vite Project
      • In your Webpack Project
    • As a Subproject of your Monorepo
      • Turborepo
      • Nx Integrated Monorepo
      • Package Manager Workspaces
  • ๐ŸŽจCustomization Strategies
    • CSS Level Customization
      • Basic example
      • Removing the default styles
      • Applying your own classes
      • Page specific styles
      • Using Tailwind
      • Using custom assets
        • .css, .sass or .less
        • CSS-in-JS
    • Component Level Customization
      • Using custom assets
  • ๐Ÿ–‹๏ธCustom Fonts
  • ๐ŸŒŽInternationalization and Translations
  • ๐ŸŽญTheme Variants
  • ๐Ÿ“Customizing the Register Page
  • ๐Ÿ‘คAccount Theme
    • Single-Page
    • Multi-Page
  • ๐Ÿ“„Terms and conditions
  • ๐Ÿ–‡๏ธStyling a Custom Page Not Included In Base Keycloak
  • ๐Ÿ”งAccessing the Server Environment Variables
  • ๐ŸŽฏTargetting Specific Keycloak Versions
  • ๐Ÿ“งEmail Customization
  • ๐Ÿš›Passing URL Parameters to your Theme
  • ๐ŸคตAdmin theme
  • ๐Ÿ“ฅImporting the JAR of Your Theme Into Keycloak
  • ๐Ÿ”›Enabling your Theme in the Keycloak Admin Console
  • ๐Ÿค“Taking ownership of the kcContext
  • ๐Ÿ“–Configuration Options
    • --project
    • keycloakVersionTargets
    • environmentVariables
    • themeName
    • startKeycloakOptions
    • themeVersion
    • postBuild
    • XDG_CACHE_HOME
    • kcContextExclusionsFtl
    • keycloakifyBuildDirPath
    • groupId
    • artifactId
    • Webpack specific options
      • projectBuildDirPath
      • staticDirPathInProjectBuildDirPath
      • publicDirPath
  • FAQ & HELP
    • ๐Ÿ˜žCan't identify the page to customize?
    • ๐Ÿค”How it Works
    • ๐Ÿ˜–Some values you need are missing from in kcContext type definitions?
    • โ“Can I use it with Vue or Angular
      • Angular
    • โš ๏ธLimitations
    • ๐Ÿ›‘Errors Keycloak in Logs
    • ๐Ÿ™‹How do I add extra pages?
    • ๐Ÿค“Can I use react-hooks-form?
    • ๐Ÿš€Redirecting you users to the login/register pages
    • ๐Ÿ’ŸContributing
    • โฌ†๏ธMigration Guides
      • โฌ†๏ธv9 -> v10
      • โฌ†๏ธCRA -> Vite
      • โฌ†๏ธv8 -> v9
      • โฌ†๏ธv7 -> v8
      • โฌ†๏ธv6 -> v7
      • โฌ†๏ธv6.x -> v6.12
      • โฌ†๏ธv5 -> v6
    • ๐ŸชGoogle reCaptcha and End of third-party Cookies
    • ๐Ÿ”–Accessing the Realm Attributes
  • โญSponsors
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Integrating Keycloakify in your Codebase
  2. As a Subproject of your Monorepo

Turborepo

Last updated 8 months ago

Was this helpful?

First you want to create a new subproject in your monorepo, just clone the starter template into apps/keycloak-theme.

cd my-turborepo
git clone https://github.com/keycloakify/keycloakify-starter apps/keycloak-theme
rm -rf apps/keycloak-theme/.git
rm -rf apps/keycloak-theme/.github

Change the name field in the package.json of your keycloakify sub app.

apps/keycloak-theme/package.json
 {
-    "name": "keycloakify-starter",
+    "name": "keycloak-theme",
 }

Give an actual name to your theme (as you want it to apprear )

apps/keycloak-theme/vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { keycloakify } from "keycloakify/vite-plugin";

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [react(), keycloakify({
        themeName: "my-app"
    })]
});

Then you want to add a new script for building your theme in your root package.json

package.json
{
  "name": "my-turborepo",
  "scripts": {
    "build": "turbo build",
    "dev": "turbo dev",
    "lint": "turbo lint",
    "format": "prettier --write \"**/*.{ts,tsx,md}\"",
    "build-keycloak-theme": "turbo run build-keycloak-theme --filter=keycloak-theme",
    "start-keycloak": "keycloakify start-keycloak -p apps/keycloak-theme"
  },
  // ...
}

Add a turborepo task

turbo.json
{
  "$schema": "https://turbo.build/schema.json",
  "tasks": {
    // ... Other tasks
    "build-keycloak-theme": {
        "outputs": [
            "dist/**", 
            "dist_keycloak/**"
        ]
    }
  }
}

You can now build your keycloak theme at the root of your monorepo by running

npm run build-keycloak-theme

Optionally, if you want to change the location of the directory where the jar for your theme are created you can do:

apps/keycloak-theme/vite.config.ts
export default defineConfig({
    plugins: [react(), keycloakify({
        themeName: "my-app",
        keycloakifyBuildDirPath: "../../dist/apps/keycloak-theme"
    })]
});
turbo.json
 {
   "$schema": "https://turbo.build/schema.json",
   "tasks": {
     // ... Other tasks
     "build-keycloak-theme": {
         "outputs": [
             "dist/**",
-            "dist_keycloak/**"
+            "../../dist/apps/keycloak-theme/**"
         ]
     }
   }
 }

If you applies those changes, when you'll run npm run build-keycloak-theme your JARs are going to be generated in dist/keycloak-theme/

  • cd apps/keycloak-theme && npx keycloakify add-story

  • npx keycloakify add-story -p apps/keycloak-theme from the root of your monorepo

When you want to use the keycloakify CLI commands you can either cd into your keycloakify sub app directory or use the . Like for example if you want to run add-story you can do either:

To go beyond the base configuration you might want to explore what are available. Starting with with keycloakVersionTargets to make sure that you only generates the JARs file you need.

๐Ÿ”ฉ
in the Keycloak Admin Console
--project option of the Keycloakify CLI
build options
๐ŸŽฏTargetting Specific Keycloak Versions
Building the theme, only compiling for Keycloak 25 with a custom jar file name. Demonstrating the effectiveness of turborepo cache