Google ReCAPTCHA v2 Integration
Project description
google-recaptcha-v2
A Reflex custom component google-recaptcha-v2.
Installation
pip install reflex-google-recaptcha-v2
Usage
Set your site key and secret key in your environment variables.
export RECAPTCHA_SITE_KEY="your-site-key"
export RECAPTCHA_SECRET_KEY="your-secret-key"
Alternatively, you can set the keys via python functions as seen in the demo app.
Place the Recaptcha component
import reflex as rx
from reflex_google_recaptcha_v2 import google_recaptcha_v2
def index():
return rx.vstack(
...,
google_recaptcha_v2(),
)
Verify the Recaptcha response
Before taking actions on the backend, you should verify that the user browser has passed validation of the token.
This value will be set for the specific tab that has completed validation and persists for the lifetime of the Reflex session (until the tab is closed).
import reflex as rx
from reflex_google_recaptcha_v2 import GoogleRecaptchaV2State
class MyState(rx.State):
form_error: str
async def handle_submit(self, form_data):
...
recaptcha_state = await self.get_state(GoogleRecaptchaV2State)
if not recaptcha_state.token_is_valid:
self.form_error = "Invalid recaptcha. Are you a robot?"
return
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file reflex-google-recaptcha-v2-0.0.3.tar.gz
.
File metadata
- Download URL: reflex-google-recaptcha-v2-0.0.3.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d50d4fd2374b002574ea58ba1f10dfcbd8d44048352bfeda893c8c747d97f6b2 |
|
MD5 | b6bce757ebdaaf2529913d3c2167d9be |
|
BLAKE2b-256 | 43b558336e059bc0386255ac98454a031c65ef899fb70e603f4f335bd08657f5 |
File details
Details for the file reflex_google_recaptcha_v2-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: reflex_google_recaptcha_v2-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07f869c29a843d7e70ab0a5fe5061b92e0b9932a76dc7ccfa651b33f8c47adfe |
|
MD5 | f68d7c56c7d1ff271679d732463bbaa7 |
|
BLAKE2b-256 | 54f1bdebc6f32f04345cde746e3218086c2e6cceddaf481599dc987a7834cef2 |