Google reCAPTCHA v3 - Frontend Integration
ES module for the Google reCAPTCHA v3 frontend integration.
Install
$ npm install --save recaptcha-frontend
Usage
Pick your favorite:
const { execute, load } = require("recaptcha-frontend");
import execute, { load } from 'recaptcha-frontend';
... then all you need is:
execute('homepage', 'site-key').then((token) => {
// Send `token` to your backend for verification.
});
execute()
will automatically load the reCAPTCHA v3 API and execute your request in a single step.
You can also preload the API and call execute()
later, without specifying your site key on every call:
load('site-key').then(() => {
// The API is loaded and ready.
});
// Do other things ...
execute('homepage').then(token => {
// Send `token` to your backend for verification.
});
API
load(siteKey, [recaptchaNet = false])
-
siteKey
(string) Your reCAPTCHA site key. -
recaptchaNet
(boolean) Whether to use the recaptcha.net alternate URL to load the API.
Returns: (Promise) The fulfillement handler (then
) is called when the API is loaded and ready.
Loads the API.
execute(action, [siteKey], [recaptchaNet = false])
-
action
(string) The action to execute. -
siteKey
(string) Your reCAPTCHA site key. If not specified, will use the last site key provided toload()
orexecute()
. -
recaptchaNet
(boolean) Whether to use the recaptcha.net alternate URL to load the API.
Returns: (Promise) The fulfillment handler (then
) receives a single token
parameter that can be used for verification.
Executes an action. Loads the API if needed.
showBadge()
Shows the reCAPTCHA badge.
hideBadge()
Hides the reCAPTCHA badge. This requires the reCAPTCHA branding to be included visibly in the user flow.