Inputs
Turnstile
Cloudflare's captcha widget that follows the theme and language, with getToken() and reset().
<script>
import { Turnstile } from "@codeatlasdev/ui/forms";
let handle = $state();
</script>
<Turnstile siteKey={PUBLIC_TURNSTILE_KEY} action="sign-in" bind:handle />
<!-- submit: handle.getToken(); failed submit: handle.reset() -->
It lives in @codeatlasdev/ui/forms, adds no dependency and loads Cloudflare’s script on demand, once per page (never on the server). It follows the colour scheme and UI language, re-renders when either changes and removes the widget on unmount. Without a siteKey it renders and loads nothing and getToken() is undefined. A token is single-use and only counts once your server verifies it: call reset() after a failed submit. Strict CSP: pass nonce, allow challenges.cloudflare.com.
Sign-in form
Cloudflare's always-pass test key.
Reference #843 · Pick in the gallery
Code
Props
| Prop | Type | Default | Description |
|---|---|---|---|
siteKey | string | undefined | Public site key. Unset: nothing renders or loads. |
action | string | undefined | Flow label, echoed when you verify. |
cData | string | undefined | Opaque data, echoed when you verify. |
theme | 'auto' | 'light' | 'dark' | 'auto' | `auto` follows the active colour scheme. |
language | string | active locale | Language tag; the UI locale in lower case (`pt-br`). |
size | 'normal' | 'flexible' | 'compact' | undefined | Widget size. |
appearance | 'always' | 'execute' | 'interaction-only' | undefined | When it is visible. |
handle | TurnstileHandle | bindable | `getToken()` and `reset()` (new challenge, clears the token). |
token | string | bindable | The current token, `undefined` while there is none. |
onverify | (token: string) => void | undefined | Called when the check passes. |
onexpire | () => void | undefined | Called when the token expires; the token is cleared. |
onerror | (code: string) => void | undefined | Widget or script failed; `code` is Cloudflare's. |
nonce | string | undefined | CSP nonce for the script tag. |
class | string | '' | Extra class names. |