Skip to content
← Templates

Knock Codes

A copy-paste React access screen for client previews and staging apps — segmented code entry, dark card, footer help text. One file, zero dependencies.

Client previewStandardtemplatesegmentedv1.1.0

Best used for A polished, on-brand access page you can ship as-is, no assembly required.

The fastest way to a fully-branded, polished access page — copy one file, wire a hash and a logo, done. Paste a code across any box and it distributes automatically across the group.

// Usage

Minimal setup

<KnockCodesTemplate expectedHash={process.env.NEXT_PUBLIC_KNOCK_HASH}>
  <YourApp />
</KnockCodesTemplate>
FIG.01Demo code: 4242
Installation

Add this template to your project

Recommended

npx shadcn@latest add @knock-codes/knock-codes-template

Also installs

  • Knock Codes Core
  • Knock Codes Types
  • useKnockCodes
  • cx (classname helper)
  • PIN Input

These install together as one atomic unit — even a presentational or read-only piece needs the full verification stack (hook, types, core) behind it to actually run.

Files created (10)

  • components/knock-codes/core/hash.ts
  • components/knock-codes/core/verify.ts
  • components/knock-codes/core/session.ts
  • components/knock-codes/core/storage.ts
  • components/knock-codes/react/types.ts
  • components/knock-codes/react/useKnockCodes.ts
  • components/knock-codes/react/KnockCodesContext.tsx
  • components/knock-codes/react/cx.ts
  • components/knock-codes/react/PinInput.tsx
  • components/knock-codes/react/KnockCodesTemplate.tsx
Other ways

GitHub shorthand

npx shadcn@latest add trivedi-vatsal/knock-codes/knock-codes-template

Copy the files by hand

  1. Open the Code tab in the preview above.
  2. Create each path listed below in your project and paste its contents in.
  3. Do the same for anything listed under “Also installs”, if present.

Installing via an AI agent?

Drop AGENTS.md into your project root — it instructs any coding agent to hash the code locally, write only the hash, and confirm the plaintext never touched a file. Thin pointer files exist for tools that read a different filename.

// Props

API reference

PropTypeDefaultDescription
expectedHashstringSHA-256 hex hash to verify against, for local mode.
verifyVerifyFnCustom async verification function, for server mode.
validateSession(session: KnockCodesSession) => boolean | Promise<boolean>Called when a session is read from storage. Return false or throw to reject it (server-mode token check).
children *ReactNodeRendered once unlocked.
logoReactNodeRendered above the heading — your own logo/wordmark. Omitted entirely if not passed.
codeLengthnumber8Total number of code boxes.
groupSizenumber4Boxes per group — a dash separates groups.
supportHrefstringRenders "Contact Support" as a link to this URL.
onContactSupport() => voidRenders "Contact Support" as a button instead of a link — e.g. to open a chat widget.
labelsKnockCodesTemplateLabelsOverrides heading, description, access-code label, support label, footer text, and every KnockCodesLabels string.
fullPagebooleantrueSet false to embed this somewhere other than a real page root (a demo, a docs preview) — drops the full-viewport (100dvh) sizing.
theme"light" | "dark"Forces light or dark presentation on its own, independent of any ancestor ".dark" class. Omit to follow the nearest ".dark" ancestor if one happens to exist.
remember"session"Persists the unlocked session across reloads within the same tab via sessionStorage. Not a security boundary — see the security model.
classNamestringExtra classes on the full-page backdrop.

Exactly one of expectedHash or verify is required.

Notes

Accessibility

Each code box has its own aria-label ("Access code character N of 8"), the group has role="group", and Backspace/Arrow-key navigation between boxes works without a mouse. Errors and the submitting state announce through a shared aria-live="polite" region, same contract as every other block.

Customization

Layout, theme, logo, support link, and footer stay in this file. Code entry is `<PinInput variant="boxes">` — installing this template also installs PIN Input. Pass `logo`, `codeLength`/`groupSize`, and `labels`. For a masked field, use Minimal Access or `<PinInput variant="field">`.

Security & Verification

Need a hash? Use the hash generator on Getting Started — computed locally, never sent anywhere.

The honest version

Knock Codes stops casual visitors, search engines, and forwarded links. Local mode does not stop anyone who opens DevTools — the hash ships in your client bundle by design. Server mode (swap one prop) hides the hash from the client; children you already bundled are still in the JavaScript, and a forged session works unless you wire validateSession. A velvet rope, with an optional real lock. Never marketed as more than that.

// Compose with

Blocks this template is built from

Drop down to these directly once you need more control than the single-file template gives you.