Skip to content
← Templates

Modal Access

A copy-paste React access screen for gating one section of a live page — a blur-overlay dialog, content stays mounted behind it. One file, zero dependencies.

Staging appAdvancedtemplatemodaloverlayv1.1.0

Best used for Gating one section of an already-public page without hiding the rest of it.

// Usage

Minimal setup

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

Add this template to your project

Recommended

npx shadcn@latest add @knock-codes/modal-access-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/ModalAccessTemplate.tsx
Other ways

GitHub shorthand

npx shadcn@latest add trivedi-vatsal/knock-codes/modal-access-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 *ReactNodeThe gated section. Stays mounted, blurred, and inert while locked — rendered normally once unlocked.
logoReactNodeRendered above the heading in the dialog — your own logo/wordmark. Omitted entirely if not passed.
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.
labelsModalAccessTemplateLabelsOverrides heading, description, input label, support label, and every KnockCodesLabels string.
fullPagebooleanfalseSet true if this template gates the entire page rather than one section, so the wrapper takes the full viewport height.
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 outer wrapper.

Exactly one of expectedHash or verify is required.

Notes

Accessibility

The dialog carries role="dialog" and aria-modal="true"; the blurred content behind it is marked aria-hidden and inert while locked, so screen readers and keyboard focus skip it entirely. The code field autofocuses when the dialog opens. Errors and the submitting state announce through a shared aria-live="polite" region, same contract as every other block.

Customization

Everything is one file — backdrop, dialog, heading, description, field, button, and support link are all inline. Unlike the other templates, `children` renders even while locked (blurred and inert) instead of being swapped out, since the point is gating a section of a page that's otherwise visible. Pass `logo` and `labels` to customize; set `fullPage` if this is the whole page rather than one section of it.

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.