A reflex-cloudflare-turnstile component for Reflex applications. Built on top of react-turnstile, it provides a smart verification with minimal user interaction.
pip install reflex-cloudflare-turnstileimport reflex as rx
import reflex_cloudflare_turnstile
from reflex_cloudflare_turnstile import turnstile, TurnstileState
if not reflex_cloudflare_turnstile.is_key_set():
reflex_cloudflare_turnstile.set_site_key(" ") # Get test site key from cloudflare website
reflex_cloudflare_turnstile.set_secret_key(" ") # Get test secret key from cloudflare website
class State(rx.State):
pass
def index() -> rx.Component:
return rx.vstack(
rx.heading("Reflex Cloudflare Turnstile Demo", size="7"),
rx.text(
"Token is valid? ",
rx.cond(TurnstileState.token_is_valid, "Yes β", "No β"),
weight="bold",
),
rx.cond(
rx.State.is_hydrated & ~TurnstileState.token_is_valid,
turnstile(),
),
rx.cond(
TurnstileState.token_is_valid,
rx.text("Verification successful!", color="green", weight="bold"),
),
height="100vh",
align="center",
justify="center",
spacing="4",
p="4",
)
app = rx.App()
app.add_page(index, title="Simple Turnstile Demo", on_load=TurnstileState.reset_validation)
Don't forget to add the frontend package to your rxconfig.py:
import reflex as rx
config = rx.Config(
app_name="cloudflare_turnstile_demo",
frontend_packages=[
"@marsidev/react-turnstile"
]
)- Initial release
- Basic cloudflare turnstile functionality
If you encounter any issues or have questions:
- Check the GitHub Issues
- Join the Reflex Discord community
- Create a new issue with detailed information
- Built with Reflex - The web framework for Python
- Powered by react-turnstile - React cloudflare turnstile component
Made with β€οΈ for the Reflex community
Star β this repo if you find it useful!
