Git Product home page Git Product logo

react-google-invisible-recaptcha's Introduction

react-google-invisible-recaptcha

A React component which is interested in only Google invisible reCAPTCHA.

  • Support multiple reCAPTCHA widgets on one page.
  • Support React hooks.
  • Support Typescript.

Migration from 0.x to 1.0.0

// Version 0.x
<Recaptcha ref={ref => this.recaptcha = ref} ... />
// this.recaptcha.execute invokes the reCAPTCHA check.

// Version 1.0.0
const refCaptcha = React.useRef(null) // or React.createRef().
<Recaptcha ref={refRecaptcha} ... />
// refRecaptcha.current.callbacks.execute invokes the reCAPTCHA check.
//             ^^^^^^^^^^^^^^^^^^

Type something in an input box and click the button to submit data. The value is then checked to make up example client-side validation. Only valid input triggers reCAPTCHA. Since the reCAPTCHA is invisible, it proceeds most likely as if none is attached. You will only be present the figure of the reCAPTCHA when Google hesitates to tell your identity.

When reCAPTCHA is resolved, the demo page shows the result token for demo purpose. In a real application, it should be used with a HTTP request targeting at https://www.google.com/recaptcha/api/siteverify?secret=<secret>&response=<token> on the server to validate the reCAPTCHA result before any sensitive operation is performed. Checking input values derived from clients on the server imporves security as well.

Example

See the example/ folder for an example.

Install

// 1.0.0 prerelease.
npm install react-google-invisible-recaptcha@next --save
npm install react-google-invisible-recaptcha --save

Usage

import Recaptcha from 'react-google-invisible-recaptcha';

<Recaptcha
  onResolved={() => console.log('Human detected.')} />
  ref={refRecaptcha}
  sitekey={<sitekey>}

Configuration

Set required props to get going.

  • sitekey: sitekey for your recaptcha. Required.

A few optional props you can tweak.

  • badge: bottomright, bottomleft, or inline. Default: bottomright.
  • locale: in which language it speaks. Default: en.
  • nonce: nonce included in the reCAPTCHA script tag. Default: undefined.
  • onExpired: callback when the recaptcha response expires. Default: noop.
  • onError: callback when the recaptcha encounters an error. Default: noop.
  • onLoaded: callback when the recaptcha is loaded. Default: noop.
  • onResolved: callback when the recaptcha is resolved. Default: noop.
  • style: custom CSS applied to the root node. Default: undefined.
  • tabindex: tabindex of the challenge. Default: 0.

APIs

// Functional component with React hooks.
const refRecaptcha = React.useRef(null);
<Recaptcha ref={refRecaptcha} ... />

// Class component.
this.refRecaptcha = React.createRef();
<Recaptcha ref={refRecaptcha} ... />

// refRecaptcha.current.callbacks.execute function which invokes the reCAPTCHA check.
// refRecaptcha.current.callbacks.reset function which resets the reCAPTCHA widget.
// refRecaptcha.current.callbacks.getResponse function which returns the response token.

License

MIT. See LICENSE.md for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.