Firebase - SPA web application - issue with logout












0














I've recently made simple SPA application which connects to firebase using Google provider and loads data for authenticated user.
Everything was great, until I tried to sign-out user using following method from documentation:



firebase.auth().signOut()


Logout was succesful, but after this, I can't sign-in again, because I'm receiving following error:




updateCurrentUser failed: First argument "user" must be an instance of Firebase User or null.




When I checked network tab in my browser, I've seen my user data in responses, so there Was an issue propably with the firebasewebui.



Things which I also tried




  • Sign-in in another browser - working

  • Sign-in in incognito mode - not working

  • Sign-in from other domain (for instance fake domain authorized in firebase console) - working

  • Wiped my entire Google Chrome profile from computer and add it again - not working

  • Sign-in from Android application - working (here there is no issue with sign-out and sign-in)


So it looks like it is something connected with domain and browser combination.



Here is my js code:



const firebase = require('firebase/app');
require('firebase/auth');
require('firebaseui');

const initializeFirebase = () => {
const config = { /* config */ };

firebase.initializeApp(config);

firebase.auth().onAuthStateChanged(function (user) {
if (user) {
// loads data
} else {
// visibility staff
initializeFirebaseAuthForm();
}
});
}

const initializeFirebaseAuthForm = () => {
const uiConfig = {
callbacks: {
signInSuccessWithAuthResult: function (authResult, redirectUrl) {
return false;
},
uiShown: function () {
visibilityManager(false);
}
},
signInFlow: 'popup',
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID
]
};

let ui = null;
if (firebaseui.auth.AuthUI.getInstance()) {
ui = firebaseui.auth.AuthUI.getInstance();
} else {
ui = new firebaseui.auth.AuthUI(firebase.auth());
}
ui.start('#firebaseui-auth-container', uiConfig);
}

document.addEventListener('DOMContentLoaded', function () {
initializeFirebase();
});


In such case, my observer registered in onAuthStateChanged is not fired.










share|improve this question
























  • Hard to say what's causing this. Can you provide a reproducible sample code or host your code somewhere accessible to facilitate debugging?
    – bojeil
    Nov 19 '18 at 19:11










  • @bojeil in the meantime, I've found answer. I posted it down below.
    – Jerzy Piechowiak
    Nov 19 '18 at 19:32
















0














I've recently made simple SPA application which connects to firebase using Google provider and loads data for authenticated user.
Everything was great, until I tried to sign-out user using following method from documentation:



firebase.auth().signOut()


Logout was succesful, but after this, I can't sign-in again, because I'm receiving following error:




updateCurrentUser failed: First argument "user" must be an instance of Firebase User or null.




When I checked network tab in my browser, I've seen my user data in responses, so there Was an issue propably with the firebasewebui.



Things which I also tried




  • Sign-in in another browser - working

  • Sign-in in incognito mode - not working

  • Sign-in from other domain (for instance fake domain authorized in firebase console) - working

  • Wiped my entire Google Chrome profile from computer and add it again - not working

  • Sign-in from Android application - working (here there is no issue with sign-out and sign-in)


So it looks like it is something connected with domain and browser combination.



Here is my js code:



const firebase = require('firebase/app');
require('firebase/auth');
require('firebaseui');

const initializeFirebase = () => {
const config = { /* config */ };

firebase.initializeApp(config);

firebase.auth().onAuthStateChanged(function (user) {
if (user) {
// loads data
} else {
// visibility staff
initializeFirebaseAuthForm();
}
});
}

const initializeFirebaseAuthForm = () => {
const uiConfig = {
callbacks: {
signInSuccessWithAuthResult: function (authResult, redirectUrl) {
return false;
},
uiShown: function () {
visibilityManager(false);
}
},
signInFlow: 'popup',
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID
]
};

let ui = null;
if (firebaseui.auth.AuthUI.getInstance()) {
ui = firebaseui.auth.AuthUI.getInstance();
} else {
ui = new firebaseui.auth.AuthUI(firebase.auth());
}
ui.start('#firebaseui-auth-container', uiConfig);
}

document.addEventListener('DOMContentLoaded', function () {
initializeFirebase();
});


In such case, my observer registered in onAuthStateChanged is not fired.










share|improve this question
























  • Hard to say what's causing this. Can you provide a reproducible sample code or host your code somewhere accessible to facilitate debugging?
    – bojeil
    Nov 19 '18 at 19:11










  • @bojeil in the meantime, I've found answer. I posted it down below.
    – Jerzy Piechowiak
    Nov 19 '18 at 19:32














0












0








0







I've recently made simple SPA application which connects to firebase using Google provider and loads data for authenticated user.
Everything was great, until I tried to sign-out user using following method from documentation:



firebase.auth().signOut()


Logout was succesful, but after this, I can't sign-in again, because I'm receiving following error:




updateCurrentUser failed: First argument "user" must be an instance of Firebase User or null.




When I checked network tab in my browser, I've seen my user data in responses, so there Was an issue propably with the firebasewebui.



Things which I also tried




  • Sign-in in another browser - working

  • Sign-in in incognito mode - not working

  • Sign-in from other domain (for instance fake domain authorized in firebase console) - working

  • Wiped my entire Google Chrome profile from computer and add it again - not working

  • Sign-in from Android application - working (here there is no issue with sign-out and sign-in)


So it looks like it is something connected with domain and browser combination.



Here is my js code:



const firebase = require('firebase/app');
require('firebase/auth');
require('firebaseui');

const initializeFirebase = () => {
const config = { /* config */ };

firebase.initializeApp(config);

firebase.auth().onAuthStateChanged(function (user) {
if (user) {
// loads data
} else {
// visibility staff
initializeFirebaseAuthForm();
}
});
}

const initializeFirebaseAuthForm = () => {
const uiConfig = {
callbacks: {
signInSuccessWithAuthResult: function (authResult, redirectUrl) {
return false;
},
uiShown: function () {
visibilityManager(false);
}
},
signInFlow: 'popup',
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID
]
};

let ui = null;
if (firebaseui.auth.AuthUI.getInstance()) {
ui = firebaseui.auth.AuthUI.getInstance();
} else {
ui = new firebaseui.auth.AuthUI(firebase.auth());
}
ui.start('#firebaseui-auth-container', uiConfig);
}

document.addEventListener('DOMContentLoaded', function () {
initializeFirebase();
});


In such case, my observer registered in onAuthStateChanged is not fired.










share|improve this question















I've recently made simple SPA application which connects to firebase using Google provider and loads data for authenticated user.
Everything was great, until I tried to sign-out user using following method from documentation:



firebase.auth().signOut()


Logout was succesful, but after this, I can't sign-in again, because I'm receiving following error:




updateCurrentUser failed: First argument "user" must be an instance of Firebase User or null.




When I checked network tab in my browser, I've seen my user data in responses, so there Was an issue propably with the firebasewebui.



Things which I also tried




  • Sign-in in another browser - working

  • Sign-in in incognito mode - not working

  • Sign-in from other domain (for instance fake domain authorized in firebase console) - working

  • Wiped my entire Google Chrome profile from computer and add it again - not working

  • Sign-in from Android application - working (here there is no issue with sign-out and sign-in)


So it looks like it is something connected with domain and browser combination.



Here is my js code:



const firebase = require('firebase/app');
require('firebase/auth');
require('firebaseui');

const initializeFirebase = () => {
const config = { /* config */ };

firebase.initializeApp(config);

firebase.auth().onAuthStateChanged(function (user) {
if (user) {
// loads data
} else {
// visibility staff
initializeFirebaseAuthForm();
}
});
}

const initializeFirebaseAuthForm = () => {
const uiConfig = {
callbacks: {
signInSuccessWithAuthResult: function (authResult, redirectUrl) {
return false;
},
uiShown: function () {
visibilityManager(false);
}
},
signInFlow: 'popup',
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID
]
};

let ui = null;
if (firebaseui.auth.AuthUI.getInstance()) {
ui = firebaseui.auth.AuthUI.getInstance();
} else {
ui = new firebaseui.auth.AuthUI(firebase.auth());
}
ui.start('#firebaseui-auth-container', uiConfig);
}

document.addEventListener('DOMContentLoaded', function () {
initializeFirebase();
});


In such case, my observer registered in onAuthStateChanged is not fired.







javascript firebase firebase-authentication google-signin firebaseui






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 16:05









Frank van Puffelen

228k28373396




228k28373396










asked Nov 18 '18 at 14:05









Jerzy PiechowiakJerzy Piechowiak

117




117












  • Hard to say what's causing this. Can you provide a reproducible sample code or host your code somewhere accessible to facilitate debugging?
    – bojeil
    Nov 19 '18 at 19:11










  • @bojeil in the meantime, I've found answer. I posted it down below.
    – Jerzy Piechowiak
    Nov 19 '18 at 19:32


















  • Hard to say what's causing this. Can you provide a reproducible sample code or host your code somewhere accessible to facilitate debugging?
    – bojeil
    Nov 19 '18 at 19:11










  • @bojeil in the meantime, I've found answer. I posted it down below.
    – Jerzy Piechowiak
    Nov 19 '18 at 19:32
















Hard to say what's causing this. Can you provide a reproducible sample code or host your code somewhere accessible to facilitate debugging?
– bojeil
Nov 19 '18 at 19:11




Hard to say what's causing this. Can you provide a reproducible sample code or host your code somewhere accessible to facilitate debugging?
– bojeil
Nov 19 '18 at 19:11












@bojeil in the meantime, I've found answer. I posted it down below.
– Jerzy Piechowiak
Nov 19 '18 at 19:32




@bojeil in the meantime, I've found answer. I posted it down below.
– Jerzy Piechowiak
Nov 19 '18 at 19:32












1 Answer
1






active

oldest

votes


















0














I've found answer by myself.
There was couple of issues. First of all, Firebase initialization should be placed as 'global' like for example here: https://github.com/firebase/firebaseui-web/, especially this lines:



firebase.initializeApp(config);
ui = new firebaseui.auth.AuthUI(firebase.auth());


Secondly, with my code from input, I've to get existing instance of ui using conditional. In firebase github, ui was created always using new operator and it was always created once per script run.
I found out, that there is workaround - ui instance can be deleted using delete() promise.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361758%2ffirebase-spa-web-application-issue-with-logout%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I've found answer by myself.
    There was couple of issues. First of all, Firebase initialization should be placed as 'global' like for example here: https://github.com/firebase/firebaseui-web/, especially this lines:



    firebase.initializeApp(config);
    ui = new firebaseui.auth.AuthUI(firebase.auth());


    Secondly, with my code from input, I've to get existing instance of ui using conditional. In firebase github, ui was created always using new operator and it was always created once per script run.
    I found out, that there is workaround - ui instance can be deleted using delete() promise.






    share|improve this answer


























      0














      I've found answer by myself.
      There was couple of issues. First of all, Firebase initialization should be placed as 'global' like for example here: https://github.com/firebase/firebaseui-web/, especially this lines:



      firebase.initializeApp(config);
      ui = new firebaseui.auth.AuthUI(firebase.auth());


      Secondly, with my code from input, I've to get existing instance of ui using conditional. In firebase github, ui was created always using new operator and it was always created once per script run.
      I found out, that there is workaround - ui instance can be deleted using delete() promise.






      share|improve this answer
























        0












        0








        0






        I've found answer by myself.
        There was couple of issues. First of all, Firebase initialization should be placed as 'global' like for example here: https://github.com/firebase/firebaseui-web/, especially this lines:



        firebase.initializeApp(config);
        ui = new firebaseui.auth.AuthUI(firebase.auth());


        Secondly, with my code from input, I've to get existing instance of ui using conditional. In firebase github, ui was created always using new operator and it was always created once per script run.
        I found out, that there is workaround - ui instance can be deleted using delete() promise.






        share|improve this answer












        I've found answer by myself.
        There was couple of issues. First of all, Firebase initialization should be placed as 'global' like for example here: https://github.com/firebase/firebaseui-web/, especially this lines:



        firebase.initializeApp(config);
        ui = new firebaseui.auth.AuthUI(firebase.auth());


        Secondly, with my code from input, I've to get existing instance of ui using conditional. In firebase github, ui was created always using new operator and it was always created once per script run.
        I found out, that there is workaround - ui instance can be deleted using delete() promise.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 19:31









        Jerzy PiechowiakJerzy Piechowiak

        117




        117






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361758%2ffirebase-spa-web-application-issue-with-logout%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?