Reputation: 3580
How to reinitialize firebase -> recaptcha (allready loaded and initialisated) to use with other callbacks ?
function my_recaptcha(my_success_callback,my_expired_callback){
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('id_container_recaptcha', {
'size': 'invisible',
'callback': function(response) {
// reCAPTCHA solved, allow user to do action.
// ...
my_success_callback.call(this,arguments);
},
'expired-callback': function() {
// Response expired. Ask user to solve reCAPTCHA again.
// ...
my_expired_callback.call(this,arguments);
}
});
}
If I try some like this
my_recaptcha(function(){
console.log('SUCCES 1')
},function(){
console.log('EXPIRED 1')
})
my_recaptcha(function(){
console.log('SUCCES 2')
},function(){
console.log('EXPIRED 2')
})
I got this error:
Uncaught Error: ReCAPTCHA has already been rendered in this element
Even if I try before grecaptcha.reset(window.recaptchaWidgetId);
Upvotes: 1
Views: 3452
Reputation: 30858
To re-instantiate a reCAPTCHA in the same element container, you have to clear it first: https://firebase.google.com/docs/reference/js/firebase.auth.RecaptchaVerifier#clear
This allows you to reinstantiate a new reCAPTCHA.
window.recaptchaVerifier.clear()
Upvotes: 3