Svelte SDK
Client-side Svelte 5 wrappers for the Zitadel login and logout components.
The Svelte SDK (@zitadel/sdk-svelte) is the single-page-app wrapper for the shared Zitadel login and logout components, built for Svelte 5. It exports ZitadelLogin, ZitadelLogout and ZitadelSession as Svelte components.
SPA proxy requirement
A Svelte single-page app has no server of its own. In development, the CLI configures a Vite proxy for /__nextgen/*. Production needs a same-origin proxy for /__nextgen/* that forwards the request and adds no credential, as the dev proxy does. The browser sends the publishable key itself. See SPAs in production.
Prerequisites
- Node.js 24 or newer. Run
node --versionto check. - Svelte 5, in an app built with Vite.
- A Zitadel project from
zitadel setup. Start the local runtime withnpx @zitadel/cli@latest start, then runnpx @zitadel/cli@latest setup --server localin your app's directory. See the Quickstart, or Add Zitadel to an existing app. - The project ID and secret. Setup writes them to
.env.localasZITADEL_PROJECT_IDandZITADEL_PROJECT_SECRET, and the project ID again asVITE_ZITADEL_PROJECT_ID, the name a Vite app exposes to the browser.
Install the SDK
Setup installs the SDK. To add it yourself, run:
pnpm add @zitadel/sdk-svelte@latestWire the SDK into your app
The CLI configures the Vite proxy, writes the app's root component (src/App.svelte) with the /login, /register and /profile pages, adds environment files, and installs the SDK.
In an existing app, the CLI edits the vite.config.* you already have. Every setup also writes zitadel.json and the .zitadel/ folder, adds its entries to .gitignore, and adds managed sections to AGENTS.md and README.md, and configures an AI agent in .mcp.json (Connect an AI agent).
Props and events
ZitadelLogin, ZitadelLogout and ZitadelSession take the props below, spelled the same in every SPA SDK. An unset prop keeps the component's own default.
| Prop | Type | Default | Components | Description |
|---|---|---|---|---|
project | ZitadelProject | unset | Login, Logout, Session | The handle that configureZitadel returns. Wins over projectId and proxyPath. |
projectId | string | unset | Login, Logout, Session | The project ID. Read when you pass no project handle. |
proxyPath | string | "/__nextgen" | Login, Logout, Session | The same-origin path the component calls. |
purpose | ZitadelFlowPurpose | "login" | Login | The purpose of the flow. |
flowName | string | unset | Login | Runs the flow definition with this name. Unset runs the project's default flow for the purpose. |
postSignInUrl | string | unset | Login | Where to navigate after a completed sign-in. If the page's next query parameter names a path on the same origin, the component goes there instead. The server SDKs' middleware sets next when a signed-out visitor requests a protected route. |
forcePostSignInUrl | boolean | false | Login | Navigates to postSignInUrl even when next names a path. Use it on a page that uses next for something of its own. |
postSignOutUrl | string | unset | Logout, Session | Where to navigate after sign-out. |
resumeFlowId | string or null | unset | Login | The ID of an existing flow to resume instead of starting a new one. Unset, null or "" falls back to the flow query parameter. An ID that no longer resolves starts a new flow. |
variant | "widget" or "page" | "widget" | Login, Session | widget is content-sized and paints no page chrome. page claims the viewport, paints the surface background and loads the brand font. On Login, page also focuses the first field. |
theme | "light", "dark" or "auto" | unset | Login, Logout, Session | The colour mode. Unset on Login follows the project's branding theme, then the variant default: dark for page, auto for widget. Logout defaults to auto. auto follows prefers-color-scheme. |
suppressHeader | boolean | false | Login, Session | Hides the component's own heading block visually but keeps it in the accessibility tree. Use it on pages that already carry the heading. |
suppressPasswordToggle | boolean | false | Login | Hides the show/hide button on password fields. |
heading | string | "Signed in as" | Session | Overrides the heading text. |
logoutLabel | string | "Sign out" | Session | Overrides the label of the sign-out action. |
locales | Record<string, Partial<Record<string, string>>> | unset | Login | Copy overrides, merged over the built-in dictionaries and keyed by primary language subtag. For example, { en: { "identifier.title": "Welcome back" } }. |
lang | string | browser language | Login | A BCP-47 language override. |
Each component event reaches the callback in the last column. The callback receives the event's detail payload.
| Event | Fires when | Detail | Components | Callback |
|---|---|---|---|---|
zitadel-flow-step | Login shows a step, including the first one. | { step } | Login | onFlowStep |
zitadel-flow-input | The visitor edits a field. | { name, value } | Login | onFlowInput |
zitadel-flow-complete | The flow reaches a terminal step. | { behavior, redirect_uri?, handoff_token?, handoff_token_expires_at? } | Login | onFlowComplete |
zitadel-flow-redirect | The component hands the browser to an identity provider. Nobody is signed in yet. | { redirect_url, step } | Login | onFlowRedirect |
zitadel-flow-error | The flow reports an error. | { message } | Login | onFlowError |
zitadel-signout | The user signs out. | { display, identifier } | Logout, Session | onSignout |
zitadel-session-error | Loading the session or signing out failed, other than with no session. | { status?, code?, message, phase } | Logout, Session | onSessionError |
handoff_token is the short-lived credential that a completed flow returns. The proxy exchanges it for a session.
<ZitadelLogin {project} theme="light" onFlowComplete={(detail) => track(detail)} />Standard HTML attributes
ZitadelLogin, ZitadelLogout and ZitadelSession also take the standard HTML attributes (class, style, id, title, slot, hidden, role, tabindex, data-* and aria-*) and pass them to the component element. You can position, style and label a component without an extra wrapper element. Nothing else reaches the element, so any other prop is ignored.
<ZitadelLogin {project} class="login" data-testid="login" aria-label="Sign in" />In Svelte, removing the title prop leaves title="null" on the element, because Svelte assigns it as a property.
How requests reach Zitadel
/__nextgen/* to Zitadel as a plain rewrite. It adds no credential: the browser sends the publishable key.Render on the server
If your app renders on the server, mount the component on the client only, after hydration. Or pass projectId and proxyPath to the ZitadelLogin wrapper as strings: it writes them as the project-id and proxy-path attributes. Use those hyphenated names only on a raw <zitadel-login> element. A component that starts before its configuration arrives shows an error instead of the flow.
Check that sign-in works
- Run
npm run dev. The app reads the variables that setup wrote to.env.local. - Open the dev server URL, usually
http://localhost:3000/register. Use the origin that setup registered:localhost, not127.0.0.1. - Register at
/register, or sign in at/login. A completed sign-in lands on/profile, which shows the signed-in session card. - Sign out from the session card. You return to
/login. - In browser automation, use shadow-DOM-aware locators, because the native inputs live inside shared web components.
If sign-in fails in development, run npx @zitadel/cli@latest doctor. doctor --fix repairs a dev proxy that an earlier setup wrote (SDK proxy).
See also
- SDK proxy: why SPAs need a same-origin
/__nextgen/*proxy and what it must do in production. - Components: the shared web components these wrappers render.
@zitadel/sdk-sveltesource.
Was this helpful?