I'm using Firebase Auth for my website and I ran into a problem. I want to avoid the automatic redirect after signing in and as far as I know, if you return false in the callback it won't redirect. My problem is that the signInSuccessWithAuthResult callback is not called. Why is it not called and is there a better way to achieve this?
window.addEventListener('load', function () {
var uiConfig = {
callbacks: {
signInSuccessWithAuthResult: function(authResult, redirectUrl) {
// User successfully signed in.
console.log("sign in success");
// don't redirect automatically
return false;
}
},
signInSuccessUrl: <I dont want to go here>,
signInOptions: [
// Leave the lines as is for the providers you want to offer your users.
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.EmailAuthProvider.PROVIDER_ID
],
// Terms of service url.
tosUrl: '<your-tos-url>',
// Privacy policy url.
privacyPolicyUrl: '<your-privacy-policy-url>'
};
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
user.getIdToken().then(function (accessToken) {
console.log("token retrieved: "+accessToken);
// Send token to your backend via HTTPS
var xhr = new XMLHttpRequest();
xhr.open('POST', '/');
xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded");
xhr.onload = function() {
console.log('Signed in as: ' + xhr.responseText);
document.getElementById('firebaseui-auth-container').hidden=true;
};
xhr.send('token=' + accessToken);
});
}
});
});
After following @bojeil tip, I updated the library and now it is working.
Note that the page is still reloading after signing in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With