Standalone Gate
A copy-paste React access screen for the fastest possible integration — wrap your app, pass a hash, done. Zero dependencies.
Best used for The fastest possible integration — wrapping an entire app with minimal configuration.
For the two-line integration: generate a hash, wrap your app, ship it. No config to reason about.
Minimal setup
<StandaloneGate expectedHash={process.env.NEXT_PUBLIC_KNOCK_HASH}>
<YourApp />
</StandaloneGate>
- components
- knock-codes
- core
- react
"use client";
import type { ReactNode } from "react";
import { KnockCodes } from "./KnockCodes.tsx";
import type { GateWrapperVariant } from "./GateWrapper.tsx";
import type { KnockCodesConfig } from "./types.ts";
export interface StandaloneGateProps extends Pick<KnockCodesConfig, "expectedHash" | "verify"> {
children: ReactNode;
/** @default "This page is protected" */
heading?: string;
/** Escape hatch for embedding a Standalone Gate somewhere other than a real app root (a demo, a docs page). @default "page" */
variant?: GateWrapperVariant;
/** @default true */
autoFocus?: boolean;
}
/**
* The fastest path to a working gate: wrap your app, pass a hash, done.
* Deliberately exposes a smaller surface than `<KnockCodes>` — no storage,
* timeout, or activity-tracking props — reach for `<KnockCodes>` directly
* once you need those.
*/
export function StandaloneGate({ children, heading, expectedHash, verify, variant, autoFocus }: StandaloneGateProps) {
return (
<KnockCodes
expectedHash={expectedHash}
verify={verify}
labels={heading ? { heading } : undefined}
variant={variant}
autoFocus={autoFocus}
>
{children}
</KnockCodes>
);
}
Add this block to your project
Recommended
npx shadcn@latest add @knock-codes/standalone-gateAlso 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/StandaloneGate.tsx
Other ways
GitHub shorthand
npx shadcn@latest add trivedi-vatsal/knock-codes/standalone-gateCopy the files by hand
- Open the Code tab in the preview above.
- Create each path listed below in your project and paste its contents in.
- Do the same for anything listed under “Also installs”, if present.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| expectedHash | string | — | SHA-256 hex hash to verify against, for local mode. |
| verify | VerifyFn | — | Custom async verification function, for server mode. |
| children * | ReactNode | — | Rendered once unlocked. |
| heading | string | "This page is protected" | Overrides just the heading — for everything else, use Knock Codes directly. |
| variant | "page" | "inline" | "page" | Escape hatch for embedding a demo somewhere other than a real app root — a docs page, this gallery's own preview. |
| autoFocus | boolean | true | Focuses the code field on mount. Off in embedded previews so a newly-rendered gate can't steal focus and scroll the page. |
Exactly one of expectedHash or verify is required.
Accessibility
Same access-code entry UI as Knock Codes — full keyboard and screen-reader support inherited, none of it re-implemented.
Customization
Deliberately a smaller prop surface than Knock Codes — just `expectedHash`/`verify`, `children`, an optional `heading`, and `autoFocus`. Reach for `<KnockCodes>` directly the moment you need storage/timeout/activity-tracking control.
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.
Used in these templates
Want the whole screen instead of assembling it yourself? These templates already build on this block.
- Knock CodesA copy-paste React access screen for client previews and staging apps — segmented code entry, dark card, footer help text. One file, zero dependencies.
- Minimal AccessA copy-paste React access screen for internal tools and quick gates — a single masked field, no frills. One file, zero dependencies.
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.
- Knock CodesA copy-paste React access screen for gating a whole page or app root — local hash or server verification, one prop swap between them. Zero dependencies.
- Embedded GateA copy-paste React access screen for gating a widget or section inside an existing layout — Knock Codes, fixed to the inline shell. Zero dependencies.