Skip to main content

Reflex custom component google-recaptcha-v2

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

reflex-google-recaptcha-v2-0.0.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file reflex-google-recaptcha-v2-0.0.1.tar.gz.

File metadata

File hashes

Hashes for reflex-google-recaptcha-v2-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cb7567ac73d0a8f02e521bd6478892cd7608fb5b77d6a3ae80b782542f14c350
MD5 dcf941358c1a1c3496f3702885a7b59e
BLAKE2b-256 2601dbb3bc9a69d21ac16f4a6456cc0d8225ac7adc3afe17b2fb517d78c1afb2

See more details on using hashes here.

File details

Details for the file reflex_google_recaptcha_v2-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for reflex_google_recaptcha_v2-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ebe39e03cbf417765b071282518d7fcec4cfb9a5274bf5945327b8f0c50a09f5
MD5 7e2c5fd1a6f1a0675c7f1aef9caee235
BLAKE2b-256 f322e6c4499ad3cd1d44a4416df7fd630279f50463c34d267e98bfb57288fff0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page