This repository demonstrates how to replace Keycloak’s built-in login UI with a custom onboarding and authentication flow implemented in SvelteKit, while still using Keycloak as the identity provider and token service.
Instead of redirecting users to Keycloak’s hosted login page, this project adds an abstraction layer that lets you present branded, multi-step onboarding and custom sign-in/sign-up forms inside your app. Authentication and token management are handled via the official keycloak-js
adapter.
keycloak-js
adapter to obtain and refresh tokens.keycloak-js
adapter to talk to Keycloak (token requests, refresh, logout).[!CAUTION] This repository is educational and demonstrates integration patterns. Replacing Keycloak’s hosted login page places responsibility for secure credential handling, password policies, and anti-abuse protections on your app. Prefer Authorization Code Flow with PKCE and/or backend-assisted exchanges for production deployments. Review Keycloak best practices before deploying.
Follow these steps to set up the SvelteKit + Keycloak Custom Onboarding example locally.
Start by cloning the project from GitHub:
git clone https://github.com/Bitxo92/keycloak_custom_onboarding.git
cd keycloak_custom_onboarding
[!NOTE] Make sure you have Node.js installed before running the setup. It’s recommended to use NVM (Node Version Manager) to easily install and manage Node.js versions across different projects.
For example:
nvm install --lts nvm use --lts
This ensures you’re running a compatible Node.js version for SvelteKit and Vite.
This project relies on Docker Desktop to spin up a local Keycloak and PostgreSQL environment.
docker pull bitnami/keycloak:latest
docker pull bitnami/postgresql:latest
docker network create keycloak_net
docker run -d \
--name keycloak_db \
--network keycloak_net \
-e POSTGRESQL_USERNAME=bn_keycloak \
-e POSTGRESQL_PASSWORD=bitnami \
-e POSTGRESQL_DATABASE=bitnami_keycloak \
bitnami/postgresql:latest
docker run -d \
--name keycloak \
--network keycloak_net \
-p 8080:8080 \
-e KEYCLOAK_DATABASE_HOST=keycloak_db \
-e KEYCLOAK_DATABASE_PORT=5432 \
-e KEYCLOAK_DATABASE_NAME=bitnami_keycloak \
-e KEYCLOAK_DATABASE_USER=bn_keycloak \
-e KEYCLOAK_DATABASE_PASSWORD=bitnami \
-e KEYCLOAK_ADMIN_USER=admin \
-e KEYCLOAK_ADMIN_PASSWORD=admin \
bitnami/keycloak:latest
Once both containers are running, open the Keycloak Admin Console at:
and log in with:
Username: admin
Password: admin
Inside the Keycloak Admin Console, perform the following setup:
myrealm
.Go to Clients → Create
Set the following:
myclient
public
(or confidential
if using backend flows)http://localhost:5173/*
[!NOTE] For local development with a Svelte frontend and Keycloak:
- Set Web Origins to
*
(to avoid CORS issues during dev).- Set Valid Redirect URIs to
http://localhost:5173/*
.- This ensures Keycloak accepts requests from your Svelte app running locally.
[!IMPORTANT] Direct access grant must be enabled for credential exchange with keycloak`s server to work from our custom login
This project uses Sveltekit with Vite. Once cloned install dependencies with:
npm install
Then run the local dev server:
npm run dev
by default, the app runs at http://localhost:5173
This project is licensed under the MIT License.