mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
267b7fc17d
[web] de-ng homepage prototype GitOrigin-RevId: 030a5bf0b4f05eac7d69fda928c906f3c9c962f0
23 lines
583 B
JavaScript
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)
|
|
})
|
|
}
|