Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

⚛ A reCAPTCHA bridge for React Native that works (Android and iOS)

License

NotificationsYou must be signed in to change notification settings

douglasjunior/react-native-recaptcha-that-works

Repository files navigation

License MITnpm versionnpm downloads


🚨 Important Notice 🚨

Users have recently observed a significant increase in "high risk requests" when using reCAPTCHA solution with WebView. Upon further investigation, we found that the official documentation advises against using WebView-based implementations for reCAPTCHA on iOS and Android.

Now, Google recommends using theirfirst-party solution for React Native, which is intended for enterprise use.

⚠️ We encourage you to try both the WebView-based solution and the first-party native library to determine which one best fits your needs.

You can find more details and the discussionhere.


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

Looking forReact DOM version?

NormalInvisible

Try theOnline demo.

Install

Install the module

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

Or

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

See thereact-native-webview Getting Started Guide.

Usage

WithJavaScript:

importReact,{useRef}from'react';import{View,Button}from'react-native';importRecaptchafrom'react-native-recaptcha-that-works';constApp=()=>{constrecaptcha=useRef();constsend=()=>{console.log('send!');this.recaptcha.current.open();}constonVerify=token=>{console.log('success!',token);}constonExpire=()=>{console.warn('expired!');}return(<View><Recaptcharef={recaptcha}siteKey="<your-recaptcha-public-key>"baseUrl="http://my.domain.com"onVerify={onVerify}onExpire={onExpire}size="invisible"/><Buttontitle="Send"onPress={send}/></View>);}
Or withTypeScript:
importReact,{useRef}from'react';import{View,Button}from'react-native';importRecaptcha,{RecaptchaRef}from"react-native-recaptcha-that-works";// ...exportconstComponent:React.FC=()=>{constrecaptcha=useRef<RecaptchaRef|null>(null);constsend=()=>{console.log('send!');recaptcha.current?.open();};constonVerify=(token:string)=>{console.log('success!',token);};constonExpire=()=>{console.warn('expired!');}return(<View><Recaptcharef={recaptcha}siteKey="<your-recaptcha-public-key>"baseUrl="http://my.domain.com"onVerify={onVerify}onExpire={onExpire}size="invisible"/><Buttontitle="Send"onPress={send}/></View>);};

For more details, see theSample Project.

Props

NameValueDefaultDescription
headerComponentReact ElementA component to render on top of Modal.
footerComponentReact ElementA component to render on bottom of Modal.
loadingComponentReact ElementA custom loading component.
styleViewStyleCustomize default style such as background color.
modalPropsModalPropsOverride the Modal props.
webViewPropsWebViewPropsOverride the WebView props.
langstringLanguage code.
siteKeystring(Required) Your Web reCAPTCHA site key. (The Web key must be used, not for Android)
baseUrlstring(Required) The URL (domain) configured in the reCAPTCHA console setup. (ex.http://my.domain.com) (See also#34)
size'invisible','normal' or'compact''normal'The size of the widget.
theme'dark' or'light''light'The color theme of the widget.
onLoadfunction()A callback function, executed when the reCAPTCHA is ready to use.
onVerifyfunction(token)(Required) A callback function, executed when the user submits a successful response. The reCAPTCHA response token is passed to your callback.
onExpirefunction()A callback function, executed when the reCAPTCHA response expires and the user needs to re-verify. Only works if thewebview still open afteronVerify has been called for a long time.
onErrorfunction(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.
onClosefunction()A callback function, executed when the Modal is closed.
recaptchaDomainstringwww.google.comThe host name of the reCAPTCHA valid api.See detail.
gstaticDomainstringwww.gstatic.comCustomize reCAPTCHAgstatic host.
hideBadgebooleanfalseWhensize = 'invisible', you are allowed to hide the badge as long as you include the reCAPTCHA branding visibly in the user flow.See detail.
enterpriseboolean (enterprise)falseUse the newreCAPTCHA Enterprise API. Note: for enterprise you need to choose thesizewhen creating thesiteKey.
actionstring (enterprise)Anadditional parameter for specifying the action name associated with the protected element for reCAPTCHA Enterprise API.

Note: Iflang is not set, then device language is used.

Methods

NameTypeDescription
openfunctionOpen the reCAPTCHA Modal.
closefunctionClose the reCAPTCHA Modal.

Note: If usingsize="invisible", then challenge run automatically whenopen is called.

reCAPTCHA v2 docs

reCAPTCHA Enterprise docs

Troubleshooting

WebView not loading on iOS

This is a bug inreact-native-webview (more details#65). PR opened inreact-native-webview/react-native-webview#3615.

reCAPTCAHsiteKey orbaseUrl invalid

This package utilizes the web version ofreCAPTCHA v2, so in thesiteKey prop you need to use thesite public key from the reCAPTCHA console.

Create new reCAPTCHA v2 herehttps://www.google.com/recaptcha/admin/create

And thebaseUrl prop must be a valid domain set in theDomains section.

Screenshot 2024-12-02 at 08 27 13

<RecaptchasiteKey="abc123"baseUrl="http://mysite.com"/>

Contribute

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

Become a Patron!Donate

License

The MIT License (MIT)Copyright (c) 2020 Douglas Nassif Roma Junior

See the fulllicense file.

About

⚛ A reCAPTCHA bridge for React Native that works (Android and iOS)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp