Keycloakify
HomeGitHubStorybookAlternative to keycloak-js
  • Documentation
  • Release Notes & Upgrade Instructions
  • FAQ
  • Frequently Asked Questions
  • How does Keycloakify work?
  • It works in Storybook but not in Keycloak
  • There is too much info exposed in window.kcContext
  • How do I identify the page to customize?
  • Can I use react-hooks-form?
  • I can't find what I need in the kcContext
  • How do I add extra pages?
  • How can I access Realm Attributes?
  • How can I redirect the user to Login/Register?
  • Errors in Keycloak Log
  • Why do I get reCaptcha warnings?
  • My Realm Overrides Translations do not apply
  • Validating the password in login-update-password.ftl page
Powered by GitBook
On this page
  • 1️⃣ Using the Bundler (Recommended)
  • 2️⃣ Using the Public Directory

Was this helpful?

Edit on GitHub

It works in Storybook but not in Keycloak

Last updated 2 months ago

Was this helpful?

If your images appear correctly in Storybook but are broken after deploying your theme to Keycloak—or when testing with npx keycloakify start-keycloak—the issue is likely due to how assets are imported.

Incorrect Import Example

The following approach is not valid for importing assets in Vite or Create React App (CRA), even outside of Keycloakify:

Component.tsx
<img src="/logo.png" />
<img src="logo.png" />

While this may work in some cases, it is unreliable and not officially supported (By Vite or Webpack).

Below are two correct ways to import assets in TypeScript files when using Vite or Create React App (this is not specific to Keycloakify, it's how it should be done in any project):

1️⃣ Using the Bundler (Recommended)

Place your logo in src/login/assets/logo.png, then import it like this:

src/login/Template.tsx
import logoPngUrl from "./assets/logo.png";

<img src={logoPngUrl} />

This method ensures that the bundler correctly resolves and includes the asset.

2️⃣ Using the Public Directory

If your logo is stored in public/img/logo.png, use one of the following approaches:

src/login/Template.tsx
<img src={import.meta.env.BASE_URL + "img/logo.png"} />
src/login/Template.tsx
import { PUBLIC_URL } from "keycloakify/PUBLIC_URL";

<img src={PUBLIC_URL + "/img/logo.png"} />

Using the public directory method is useful when assets should remain unchanged after the build process, but for most cases, bundling assets (Method 1) is the preferred approach.


By following these guidelines, your assets will load correctly in both Storybook and Keycloak.

🛑