Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install Google-Recaptcha from npm

I'm implementing recaptcha in my webapp in some forms.

I already implement my backend part and i'm right now trying to install recapatcha api.

Unfornatly, I do not find an official package in npm from google.

Should I use the package googleapis that include recpatcha or should I include this script :

 <script src="https://www.google.com/recaptcha/api.js" async defer></script>

I'm asking this because I build my script files ( including all vendors coming from npm ) with Webpack.

like image 608
OrcusZ Avatar asked Jun 20 '17 14:06

OrcusZ


1 Answers

You can just use google reCAPTCHA v3 without any npm hassle.

Register from here : https://www.google.com/recaptcha/admin/create

Then for front-end:

<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 your intent

  <script>
  grecaptcha.ready(function() {
      grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'});
  });
  </script>
like image 199
ASHu2 Avatar answered Nov 13 '22 18:11

ASHu2