0
import React from "react";
import {GoogleReCaptchaProvider, GoogleReCaptcha } from "react-google-recaptcha-v3";

class Login extend React.Component {
   verifyCallback = (response) => {
    // API call to verify the token
   }

    render() {
       return (
          // Here comes a component with email/password and login button
           ....
          <GoogleReCaptchaProvider 
            reCaptchaKey="your-site-key"
            render="explicit">
            <GoogleReCaptcha
                onVerify={this.verifyCallback}
            />
         </GoogleReCaptchaProvider>
       );
   }
}

这里,verifyCallback 是在组件第一次加载时触发的。

每次点击登录按钮如何触发verifyCallback?

4

1 回答 1

0

诗人在这里想表达的是不同的。

验证令牌是站点令牌。发送给 Google 进行验证的站点令牌。您需要调用 Javascript 方法来完成您的安全性。

  window.grecaptcha.ready(function() {
      window.grecaptcha.execute('site token', {action: action}).then(function(value) {
        token.currentRecaptchaToken = value;
        console.log(token);
      });
    });
于 2019-12-13T06:33:19.937 回答