Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase signInSuccessWithAuthResult not called

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);
           });
         }
     });
});
like image 339
Bas Avatar asked Aug 23 '18 16:08

Bas


1 Answers

After following @bojeil tip, I updated the library and now it is working.

Note that the page is still reloading after signing in.

like image 79
Bas Avatar answered Oct 29 '22 16:10

Bas