react-native-recaptcha-net-that-works
TypeScript icon, indicating that this package has built-in type declarations

1.2.0-1 • Public • Published

reCAPTCHA.net for React Native (Android and iOS)

License MIT npm version npm downloads

A reCAPTCHA.net library for React Native (Android and iOS) that works.

Normal Invisible

Looking for React DOM version?

Install

Install the module

  yarn add react-native-recaptcha-net-that-works react-native-webview

Or

  npm i -S react-native-recaptcha-net-that-works react-native-webview

See the react-native-webview Getting Started Guide.

Usage

With JavaScript:

import React, { useRef } from 'react';
import { View, Button } from 'react-native';

import Recaptcha from 'react-native-recaptcha-net-that-works';

const App = () => {
    const recaptcha = useRef();

    const send = () => {
        console.log('send!');
        this.recaptcha.current.open();
    }

    const onVerify = token => {
        console.log('success!', token);
    }

    const onExpire = () => {
        console.warn('expired!');
    }

    return (
        <View>
            <Recaptcha
                ref={recaptcha}
                siteKey="<your-recaptcha-public-key>"
                baseUrl="http://my.domain.com"
                onVerify={onVerify}
                onExpire={onExpire}
                size="invisible"
            />
            <Button title="Send" onPress={send} />
        </View>
    );
}
Or with TypeScript:
import React, { useRef } from 'react';
import { View, Button } from 'react-native';

import Recaptcha, { RecaptchaHandles } from "react-native-recaptcha-net-that-works";

// ...

export const Component: React.FC = () => {
    const recaptcha = useRef<RecaptchaHandles>();

    const send = () => {
        console.log('send!');
        recaptcha.current?.open();
    };

    const onVerify = (token: string) => {
        console.log('success!', token);
    };

    const onExpire = () => {
        console.warn('expired!');
    }

    return (
        <View>
            <Recaptcha
                ref={recaptcha}
                siteKey="<your-recaptcha-public-key>"
                baseUrl="http://my.domain.com"
                onVerify={onVerify}
                onExpire={onExpire}
                size="invisible"
            />
            <Button title="Send" onPress={send} />
        </View>
    );
};

For more details, see the Sample Project or try the Online demo.

Props

Name Value Default Description
headerComponent React Element A component to render on top of Modal.
footerComponent React Element A component to render on bottom of Modal.
loadingComponent React Element A custom loading component.
style ViewStyle Customize default style such as background color.
modalProps ModalProps Override the Modal props.
webViewProps WebViewProps Override the WebView props.
lang string Language code.
siteKey string (Required) Your sitekey.
baseUrl string (Required) The URL (domain) configured in the reCAPTCHA setup. (ex. http://my.domain.com)
size 'invisible', 'normal' or 'compact' 'normal' The size of the widget.
theme 'dark' or 'light' 'light' The color theme of the widget.
onLoad function() A callback function, executed when the reCAPTCHA is ready to use.
onVerify function(token) (Required) A callback function, executed when the user submits a successful response. The reCAPTCHA response token is passed to your callback.
onExpire function() A callback function, executed when the reCAPTCHA response expires and the user needs to re-verify.
onError function(error) A callback function, executed when reCAPTCHA encounters an error (usually network connectivity) and cannot continue until connectivity is restored. If you specify a function here, you are responsible for informing the user that they should retry.
onClose function() A callback function, executed when the Modal is closed.
enterprise boolean false (Experimental) Use the new reCAPTCHA Enterprise API.

Note: If lang is not set, then device language is used.

Methods

Name Type Description
open function Open the reCAPTCHA Modal.
close function Close the reCAPTCHA Modal.

Note: If using size="invisible", then challenge run automatically when open is called.

reCAPTCHA v2 docs

reCAPTCHA Enterprise docs

Contribute

New features, bug fixes and improvements are welcome! For questions and suggestions, use the issues.

Become a Patron! Donate

License

The MIT License (MIT)

Copyright (c) 2020 Douglas Nassif Roma Junior

See the full license file.

Package Sidebar

Install

npm i react-native-recaptcha-net-that-works

Weekly Downloads

0

Version

1.2.0-1

License

MIT

Unpacked Size

24.2 kB

Total Files

10

Last publish

Collaborators

  • n4zim