In your Vite Project
Last updated
Was this helpful?
Last updated
Was this helpful?
If you have a Vite/React/TypeScript project you can integrate Keycloakify directly inside it.
In this guide we're going to work with a vanilla Vite project.
Let's start by installing Keycloakify (and optionally Storybook) to our project:
Now you want to modify your entry point so that:
If the kcContext global is defined, render your Keycloakify theme
Else, reder your App as usual.
Let's say, for example, your src/main.tsx file currently looks like this:
You want to rename this file to src/main.app.tsx (for example) and modify it as follow:
Then you want to create the following src/main.tsx file, you can copy paste the following code, it does not need to be adapted:
Finally you want to add to your package.json a script for building the theme and another one to start storybook.
Last step is to exclude from your html <head />
things that aren't relevant in the context of Keycloak pages.
Do not blindly copy paste, this is just an example!
You have to figure out what does and does not make sense to be in the <head/> of your Keycloak UI pages.
In the above example we tell keycloakify not to include the <title>
because keycloakify will set it dynamically to something like "ACME- Login" or "ACME - Register".
We also exclude a placeholder script for injecting environment variables at container startup.
You can run npm run build-keycloak-theme, the JAR distribution of your Keycloak theme will be generated in dist_keycloak.
You're now able to use all the Keycloakify commands (npx keycloakify --help
) from the root of your project.
Next we want to repatriate the relevant files from into our project:
If you have some top level await
and you don't know how to deal with theses, join , I can help you out.
You also need to use Keycloakify's Vite plugin. Here we don't provide any but you probably at least want to define .
Leave accountThemeImplementation set to "none" for now. To initialize the account theme refer to .
That's it, your project is ready to go!
If you're currently using or to manage user authentication in your app you might want to checkout , the alternative from the Keycloakify team.
If you have any issues ! We're here to help!