Knock Codes
Knock Codes is a copy-paste "enter a code to continue" screen for private previews, staging links, internal tools, and client review pages. It is not a login system or auth provider.
Pick a template, paste it into your project, drop in a hash of your access code, and ship. That's the
whole integration: no account, no backend, and no package living in your node_modules unless you want
one. Every line you ship is yours to read, edit, and own — inspired by
and .
Knock Codes ships components like <KnockCodes> and useKnockCodes, distributed under the
@knock-codes/core and @knock-codes/react packages — see below.
When to use this
- Keeping a client preview or staging deploy off search engines and unlisted-but-guessable links.
- A soft gate in front of an internal tool or dashboard that doesn't need real user accounts.
- A "coming soon" or private-beta screen you want gone in five minutes, not five hours.
- Friction for casual visitors and forwarded links — a velvet rope, not a vault door.
When not to use this
- Protecting paid content, private user data, or anything with per-user permissions — this has no concept of a "user," only a shared code.
- Admin authorization or anything gating a real write path — pair with real auth instead.
- Compliance-sensitive data (health records, financial data, PII at rest) — local mode's hash ships in the client bundle by design; anyone can read it in DevTools.
- Anywhere the cost of someone bypassing the gate is high. If that's true for you, use server mode instead of local mode, or skip this entirely for a real auth provider.
See apps/web/app/security [blocked] (the site's /security page) for the full threat
model, including what server mode changes and doesn't.
Quickstart
-
Hash an access code.
sha256Hexfrom@knock-codes/core(or the generator on/getting-started) turns a plaintext code into a hex hash. Only the hash ever goes in your source or env vars — never the plaintext. -
Copy a template — pick one from below and either paste the file or install it with the shadcn CLI:
Installing more than one item, or from a script? Register
@knock-codesonce in your project'scomponents.jsonand install by short name from then on — no listing on the shadcn registry directory required, this talks straight toknock.codes: -
Wire the hash through a public env var (
NEXT_PUBLIC_KNOCK_CODES_HASH,VITE_KNOCK_CODES_HASH, …): -
Choose storage and timeout behavior — memory,
localStorage, orsessionStorage, and a fixed or sliding session timeout. Every template defaults to something reasonable; override via props. -
Upgrade to server verification when it matters. Swap
expectedHashfor averifyfunction pointing at a small endpoint — same component, one prop different. Reference implementations for Next.js, Cloudflare Workers, Azure Functions, Express, and Hono live incontent/server-templates[blocked].
The full walkthrough, with a live hash generator, is at
apps/web/app/getting-started [blocked] (the site's /getting-started page).
What's inside
Templates
Complete, single-file screens — call useKnockCodes directly, no other block imports required.
Blocks
Composable primitives for building a custom gate instead of using a full-page template.
Browse live, interactive previews and copy-paste source for every block and template at .
Local vs. server mode
Both modes render the same component with the same markup — only the prop differs. See
apps/web/app/security [blocked] for the full comparison and rate-limiting guidance.
Structure
packages/core— framework-agnostic hash/session/storage/verify logic, no UI.packages/react— the React blocks (<KnockCodes>,useKnockCodes, PIN Input, Protected Route/Layout/Modal/Card, Session Provider, and the ready-made templates), built onpackages/core.registry/react/registry.json— shadcn-compatible registry entries. Rebuild withnode scripts/build-registry.mjsafter editing.content/blocks/*.mdx— block metadata/docs (frontmatter: category, tags, props, accessibility, customization) — drives the Blocks gallery.content/templates/*.mdx— same shape, for Templates (complete, single-file screens) — kept separate from Blocks, not mixed in.content/server-templates— reference server-mode verify implementations (Next.js route handler, Cloudflare Worker, Azure Function, Express, Hono).apps/web— the site: block/template gallery, live previews, copy-paste source, and docs.
Develop
See for adding a new block or template, the versioning model for registry changes, and the accessibility checklist every interactive component is held to.
Publishing the registry
registry/react/registry.json is the source of truth. Building turns it into per-item JSON files under
apps/web/public/r/react, which the site serves at a stable URL for shadcn add:
Always run registry:build (and commit the result) after editing registry/react/registry.json, then run
registry:check before pushing — there's no build step that does this for you automatically.
Installing a block or template with the shadcn CLI:
Production builds default every install command shown on the site to https://knock.codes automatically —
set NEXT_PUBLIC_SITE_URL (e.g. in apps/web/.env.local or your host's env config, see apps/web/.env.example)
only if you're deploying this site to a different origin (a fork, a preview URL). In local dev, commands show
the localhost:3000 registry unless you override it the same way.
License
©