@yingzhixiaoyi/turnstile
v0.0.1
Published
Cloudflare Turnstile browser runtime and host delegation
Downloads
15
Readme
@yingzhixiaoyi/turnstile
Cloudflare Turnstile 的无框架浏览器运行时包。
能力边界
负责官方脚本加载、顶层 widget 渲染、状态回调、并发保护、Wujie delegate 和开发请求字段清理。
不负责 sitekey 配置、服务端 token 校验、登录业务、Wujie bus、Vue UI 或 Toast。
import { requestTurnstileVerification } from '@yingzhixiaoyi/turnstile'
requestTurnstileVerification({
requestId: crypto.randomUUID(),
sitekey: import.meta.env.VITE_TURNSTILE_SITE_KEY,
delegateToMain: payload => bus.toMain('turnstile-run', payload),
onReply: result => submitTokenToServer(result.token),
})主应用处理 turnstile-run 时调用 runTurnstileInHostWindow;standalone 页面不传 delegate。
安全注意:客户端 token 必须由服务端向 Cloudflare 校验;不要把 token 写入日志,也不要在生产环境使用测试 sitekey。
