Created
May 19, 2020 05:34
-
-
Save Maxim-Kolmogorov/1bfe3de25cc8a5270ed0a1417a8a3f81 to your computer and use it in GitHub Desktop.
The second implementation option for the article: https://kolmogorov.pro/integration_google_recaptcha_v3_in_site_on_vue_js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let reCaptcha = new Promise((resolve, reject) => { | |
const $script = document.createElement('script') | |
$script.src = 'https://www.google.com/recaptcha/api.js?render=ВАШ_КЛЮЧ' | |
resolve(document.head.appendChild($script)); | |
setTimeout(() => reject(new Error("Google reCaptcha не инициализирована")), 3000); | |
}); | |
reCaptcha | |
.then( | |
result => { | |
setTimeout(() => { | |
grecaptcha.ready(function() { | |
grecaptcha.execute('ВАШ_КЛЮЧ', {action: 'homepage'}).then(function(token) { | |
axios | |
.post('/functions/recaptcha.php', { | |
token: token | |
}) | |
.catch(() => { | |
console.log('POST-запрос в API Google не был отправлен.'); | |
}) | |
}); | |
}); | |
}, 1000) | |
}, | |
error => { | |
console.log(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment