Initially, my main concern was ensuring that all the Firebase scripts were properly loaded in the correct order.
To tackle this issue, I came up with a simple yet effective solution :)
var my_firebase_init = function(){
firebase.initializeApp(my_firebase_config);
firebase.auth().languageCode = my_lang;
console.log('FIREBASE INIT OK');
}
var firebase_version = 'https://www.gstatic.com/firebasejs/4.6.2/';
var scripts = [
firebase_version+'firebase.js',
firebase_version+'firebase-app.js',
firebase_version+'firebase-auth.js',
'my_firebase_init'
];
var script_loaded = [];
var deferred = new $.Deferred(),
pipe = deferred;
$.each(scripts , function(index, script) {
pipe = pipe.pipe(function() {
if(script == 'my_firebase_init'){
if(script_loaded[0] && script_loaded[1] && script_loaded[2]){
my_firebase_init();
}
return;
}
return $.getScript(script)
.done(function( script, textStatus ) {
script_loaded[index] = true
})
.fail(function( jqxhr, settings, exception ) {
script_loaded[index] = false
});
});
});
deferred.resolve();
After setting this up, now I am able to see console.log('FIREBASE INIT OK')
Next, I experimented with integrating Google reCAPTCHA like so:
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('id_container_recaptcha', {
'size': 'invisible',
'callback': function(response) {
// reCAPTCHA solved, allow user to do action.
// ...
},
'expired-callback': function() {
// Response expired. Ask user to solve reCAPTCHA again.
// ...
}
});
While this setup was functioning well, occasionally an error message would pop up:
No firebase.app.App instance is currently initialized
I observed that by waiting and retrying, the issue would resolve itself!
Hence my inquiry: Is there a way to verify if firebase.app.App has been initialized?