Docs

Qwik Router SDK

An onRequest plugin and helpers for Qwik Router (formerly Qwik City) applications.

The Qwik Router SDK is an onRequest plugin that proxies and verifies sessions on the server. The login and logout widgets come from the Qwik SDK.

Qwik 2 required

The SDK peers Qwik 2: @qwik.dev/core and @qwik.dev/router (Qwik Router, which Qwik 2 renamed from Qwik City). A Qwik 1 app (@builder.io/qwik-city) is not supported, because the widgets need Qwik 2. Migrate the app to @qwik.dev/* first. The CLI scaffolds new apps on Qwik 2.

Install

Install both packages as dev dependencies. Qwik bundles devDependencies into the server build, and its starter vite.config.ts refuses to start when a package is listed in both sections.

pnpm add -D @zitadel/sdk-qwik-router@latest @zitadel/sdk-qwik@latest

Setup

The CLI adds the plugin, the routes, environment files, and both SDK packages. No config file changes: Qwik Router picks up plugin@*.ts route files on its own.

src/routes/plugin@nextgen.ts
src/routes/index.tsx
src/routes/login/index.tsx
src/routes/register/index.tsx
src/routes/profile/index.tsx
.env.local
.env.example
package.json

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.

Runtime model

The plugin proxies same-origin /__nextgen/* requests to the backend, attaching the project secret only to the session handoff.
It verifies the session token and stores the result on the request's sharedMap; read it with getAuth(ev) in a routeLoader$, action, or endpoint.
It redirects unauthenticated requests for protectedRoutes to loginPath, with the requested path and query string in ?next=, where the login widget returns after sign-in. A route matches with or without a trailing slash, since Qwik Router serves /profile/ by default.

Verify

  • Start the app with npm run dev. Setup already wrote the URL, the secret, and the project id to .env.local.
  • Visit /login and register a user.
  • Confirm /profile shows signed-in state.
  • Log out and confirm /profile redirects to /login.

See also

Was this helpful?