Skip to content

Embedded Gate

A copy-paste React access screen for gating a widget or section inside an existing layout — Knock Codes, fixed to the inline shell. Zero dependencies.

Routing & LayoutWrapper Aliaslayout

Best used for Gating one section of a longer page — a sidebar widget or a mid-page panel.

The section-level counterpart to Standalone Gate's whole-app usage — same component, contained footprint.

// Usage

Minimal setup

<EmbeddedGate expectedHash={process.env.NEXT_PUBLIC_KNOCK_HASH}>
  <SidebarWidget />
</EmbeddedGate>
FIG.01Demo code: 4242

Sits inline inside existing layout:

Installation

Add this block to your project

Recommended

npx shadcn@latest add @knock-codes/embedded-gate

Also installs

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

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 (12)

  • 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/GateWrapper.tsx
  • components/knock-codes/react/PinInput.tsx
  • components/knock-codes/react/KnockCodes.tsx
  • components/knock-codes/react/EmbeddedGate.tsx
Other ways

GitHub shorthand

npx shadcn@latest add trivedi-vatsal/knock-codes/embedded-gate

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.
// Props

API reference

PropTypeDefaultDescription
expectedHashstringSHA-256 hex hash to verify against, for local mode.
verifyVerifyFnCustom async verification function, for server mode.
storage"localStorage" | "sessionStorage" | "memory""localStorage"Where the unlocked session persists.
timeoutnumber1800000Session lifetime in milliseconds.
children *ReactNodeRendered once unlocked.
labelsKnockCodesLabelsOverrides for every user-facing string.

Exactly one of expectedHash or verify is required.

Notes

Accessibility

Identical to Knock Codes — only the outer positioning changes, not the semantics or keyboard flow.

Customization

Same full prop surface as Knock Codes, minus `variant` (fixed to "inline"). Use it for a sidebar widget or a gated section partway down a longer page, where a full-viewport takeover would be wrong.

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 that pair well with this one

These combine naturally with this block, whether as a shared shell, a shared session, or a common fallback.