How to install google-recaptcha from npm
I am implementing recaptcha in my webapp in some forms.
I am already implementing my internals and I am currently trying to install the recapatcha api.
Unfornatly, I didn't find an official package on npm from google.
Should I use the googleapis package that includes recpatcha or should I include this script:
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
I am asking this because I am generating my script files (including all vendors coming from npm) using Webpack .
+4
source to share
1 answer
You can just use Google ReCAPTCHA v3 without any npm hassle.
Register here: https://www.google.com/recaptcha/admin/create
Then for the frontend:
<script src="https://www.google.com/recaptcha/api.js?render=reCAPTCHA_site_key"></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'}).then(function(token) {
...
});
});
</script>
In v3 you can define your actions or pass yours intent
<script>
grecaptcha.ready(function() {
grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'});
});
</script>
0
source to share