Adding your Logo
Practical example of how to import custom assets in ejected components.
Last updated
Was this helpful?
Practical example of how to import custom assets in ejected components.
Last updated
Was this helpful?
Let's say you want to put the logo of your company on every pages of the theme.
First you'd eject the Template:
This will create a src/login/Template.tsx file in your project.
Now we can use the asset in our component:
Result:
Some pepoles want to be able to "hot swipe" the asset in the Keycloak file system without having to re-build the theme and re-deploy it.
To ensure that the assets are located in a predictible location you would use the public/ directory.
Move the file to public/img/logo.png.
Then make an absolute import from your component:
It's important that you do not simply harcode src="/img/logo.png"
, or keycloakify won't be able to patch the URL for Keycloak. Use Vite's builtin import.meta.env.BASE_URL
.
Doing this is a good practice in any Vite project (not specially Keycloakify) since it ensure the correctness of your URLs even if you customize the base
parameter in the your vite.config.ts. Hard coding "/img/logo.png"
only works when base is "/"
(which is the default)
If you ever need to SSH into the Keycloak server and hot swipe the image you can find it at
Let's use this placeholder for the demo: and save it in src/login/assets/logo.png.
/opt/keycloak/themes//login/resources/dist/img/logo.png