Session

Logout Button

Reads the shared session from a Session Provider and clears it on click.

sessionaction

Best used for Any screen sharing a Session Provider session that needs a manual way to lock again.

Requires a <SessionProvider> ancestor — a logout action only makes sense where a session is already being shared with something else that reads it.

Loading preview…
Installation

Add this block to your project

CLI

npx shadcn@latest add http://localhost:3000/r/react/logout-button.json

Running this site somewhere other than localhost? Set NEXT_PUBLIC_SITE_URL and this command switches to that host automatically.

Also installs

  • Knock Codes Core
  • Knock Codes Types
  • useKnockCodes
  • Session Provider
  • cx (classname helper)

Files created (9)

  • 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/KnockCodesProvider.tsx
  • components/knock-codes/react/cx.ts
  • components/knock-codes/react/LogoutButton.tsx

No CLI? 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
childrenReactNode"Log out"Button label.
classNamestringExtra classes on the button.
onLoggedOut() => voidCalled after the shared session is cleared.
Notes

Accessibility

A real <button>, not a link or div — full keyboard operability and screen-reader semantics for free.

Customization

Pass children to change the label, or `onLoggedOut` to run something after the session clears (redirect, analytics, whatever your app needs).

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.