V
V
Viktor Shcherbakov2019-06-27 12:33:53
JavaScript
Viktor Shcherbakov, 2019-06-27 12:33:53

How to update reCaptcha v3 Token?

There is a login form, standard fields (login, password) and set recaptcha v3. Everything works, but if a person entered the login and password incorrectly, then the token (reCaptcha) does not change, and as a result, an error occurs on the second request.

The login request is made via ajax.

grecaptcha.ready(function () {
            grecaptcha.execute('6LeK7**********660SKbB0U-m0*************', { action: 'login' }).then(function (token) {
                var recaptchaResponse = document.getElementById('recaptchaResponse');
                recaptchaResponse.value = token;
            });
        });


Actually the question is how to update the reCaptcha token at the time of an error from the server?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FKV, 2019-07-02
@FKV

Paste in the ajax request handler:

grecaptcha.execute('6LeK7**********660SKbB0U-m0*************', { action: 'login' }).then(function (token) {
                var recaptchaResponse = document.getElementById('recaptchaResponse');
                recaptchaResponse.value = token;
            });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question