overleaf/services/web/frontend/js/features/form-helpers/captcha.js
Jakob Ackermann 267b7fc17d Merge pull request #4941 from overleaf/jpa-as-homepage-prototype
[web] de-ng homepage prototype

GitOrigin-RevId: 030a5bf0b4f05eac7d69fda928c906f3c9c962f0
2021-09-09 08:03:04 +00:00

23 lines
583 B
JavaScript

const grecaptcha = window.grecaptcha
let recaptchaId
const recaptchaCallbacks = []
export async function validateCaptchaV2() {
if (typeof grecaptcha === 'undefined') {
return
}
if (recaptchaId === undefined) {
const el = document.getElementById('recaptcha')
recaptchaId = grecaptcha.render(el, {
callback: token => {
recaptchaCallbacks.splice(0).forEach(cb => cb(token))
grecaptcha.reset(recaptchaId)
},
})
}
return await new Promise(resolve => {
recaptchaCallbacks.push(resolve)
grecaptcha.execute(recaptchaId)
})
}