Why firebase signInWithEmailAndPassword doesn't trigger onAuthChange?What is JSONP, and why was it created?Why does Google prepend while(1); to their JSON responses?Why does ++[[]][+[]]+[+[]] return the string “10”?Add Extra Details on Firebase User TableFirebase authentication (is not a function, is not a constructor)How to disable Signup in Firebase 3.xFirebase WEB - Email Verification not being sent. What's wrong with the codeFirebase Google Auth users not showing in Firebase Consolefirebase users login through mobileFirebase auth doesn't retain the login details in firebase web

How to write a convincing religious myth?

How far would a landing Airbus A380 go until it stops with no brakes?

Multicolumn Output

Is it okay to have a sequel start immediately after the end of the first book?

How precise must a satellite's orbit be?

How do you play "tenth" chords on the guitar?

Equilibrium constant for a solid-solid equilibrium

Extracting data from Plot

Do empty drive bays need to be filled?

Could a person damage a jet airliner - from the outside - with their bare hands?

Comparing arithmetic complexity of FFT radix-2 and convolution

Grep Match and extract

Confused with atmospheric pressure equals plastic balloon’s inner pressure

I've been given a project I can't complete, what should I do?

Latex - unable to get proper boxes

Who is "He that flies" in Lord of the Rings?

Increase speed altering column on large table to NON NULL

Make Gimbap cutter

What differences exist between adamantine and adamantite in all editions of D&D?

Housemarks (superimposed & combined letters, heraldry)

How do we say "within a kilometer radius spherically"?

Does the new finding on "reversing a quantum jump mid-flight" rule out any interpretations of QM?

How to avoid typing 'git' at the begining of every Git command

Are polynomials with the same roots identical?



Why firebase signInWithEmailAndPassword doesn't trigger onAuthChange?


What is JSONP, and why was it created?Why does Google prepend while(1); to their JSON responses?Why does ++[[]][+[]]+[+[]] return the string “10”?Add Extra Details on Firebase User TableFirebase authentication (is not a function, is not a constructor)How to disable Signup in Firebase 3.xFirebase WEB - Email Verification not being sent. What's wrong with the codeFirebase Google Auth users not showing in Firebase Consolefirebase users login through mobileFirebase auth doesn't retain the login details in firebase web






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have the following function triggered when an user logs in:



const auth = firebase.auth();

export const signIn = ( email, password ) => (
auth.signInWithEmailAndPassword( email, password )
.catch(e => e ? console.log(e) : console.log(auth.currentUser))
);


If I type in incorrect details, the error is logged into the console, but if the details are correct, nothing happens.



When I check the network data in devtools, the request returns all the data it should, but inside the app, auth.currentUser is undefined (checked after log-in as well).



And as it's not too suprising,



export const getUser = () => (
async dispatch => (
auth.onAuthStateChanged(user =>
const uid = user = ;
console.log(user)
if (uid)
console.log(uid)
dispatch(
setUserId(
uid
)
)
else
console.log("nologin")

)
)
);


just gets triggered initially, when the app loads, with undefined and nologin. Inside the firebase console, authentication with email and password enabled, and the users are valid. I know it should work, as I made many authentication process through firebase, in the same way, so I can't provide more information, if you had the same problem, and you solved it, please let me know.










share|improve this question






























    1















    I have the following function triggered when an user logs in:



    const auth = firebase.auth();

    export const signIn = ( email, password ) => (
    auth.signInWithEmailAndPassword( email, password )
    .catch(e => e ? console.log(e) : console.log(auth.currentUser))
    );


    If I type in incorrect details, the error is logged into the console, but if the details are correct, nothing happens.



    When I check the network data in devtools, the request returns all the data it should, but inside the app, auth.currentUser is undefined (checked after log-in as well).



    And as it's not too suprising,



    export const getUser = () => (
    async dispatch => (
    auth.onAuthStateChanged(user =>
    const uid = user = ;
    console.log(user)
    if (uid)
    console.log(uid)
    dispatch(
    setUserId(
    uid
    )
    )
    else
    console.log("nologin")

    )
    )
    );


    just gets triggered initially, when the app loads, with undefined and nologin. Inside the firebase console, authentication with email and password enabled, and the users are valid. I know it should work, as I made many authentication process through firebase, in the same way, so I can't provide more information, if you had the same problem, and you solved it, please let me know.










    share|improve this question


























      1












      1








      1


      1






      I have the following function triggered when an user logs in:



      const auth = firebase.auth();

      export const signIn = ( email, password ) => (
      auth.signInWithEmailAndPassword( email, password )
      .catch(e => e ? console.log(e) : console.log(auth.currentUser))
      );


      If I type in incorrect details, the error is logged into the console, but if the details are correct, nothing happens.



      When I check the network data in devtools, the request returns all the data it should, but inside the app, auth.currentUser is undefined (checked after log-in as well).



      And as it's not too suprising,



      export const getUser = () => (
      async dispatch => (
      auth.onAuthStateChanged(user =>
      const uid = user = ;
      console.log(user)
      if (uid)
      console.log(uid)
      dispatch(
      setUserId(
      uid
      )
      )
      else
      console.log("nologin")

      )
      )
      );


      just gets triggered initially, when the app loads, with undefined and nologin. Inside the firebase console, authentication with email and password enabled, and the users are valid. I know it should work, as I made many authentication process through firebase, in the same way, so I can't provide more information, if you had the same problem, and you solved it, please let me know.










      share|improve this question
















      I have the following function triggered when an user logs in:



      const auth = firebase.auth();

      export const signIn = ( email, password ) => (
      auth.signInWithEmailAndPassword( email, password )
      .catch(e => e ? console.log(e) : console.log(auth.currentUser))
      );


      If I type in incorrect details, the error is logged into the console, but if the details are correct, nothing happens.



      When I check the network data in devtools, the request returns all the data it should, but inside the app, auth.currentUser is undefined (checked after log-in as well).



      And as it's not too suprising,



      export const getUser = () => (
      async dispatch => (
      auth.onAuthStateChanged(user =>
      const uid = user = ;
      console.log(user)
      if (uid)
      console.log(uid)
      dispatch(
      setUserId(
      uid
      )
      )
      else
      console.log("nologin")

      )
      )
      );


      just gets triggered initially, when the app loads, with undefined and nologin. Inside the firebase console, authentication with email and password enabled, and the users are valid. I know it should work, as I made many authentication process through firebase, in the same way, so I can't provide more information, if you had the same problem, and you solved it, please let me know.







      javascript firebase firebase-authentication






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 21:32









      Doug Stevenson

      93.2k10106126




      93.2k10106126










      asked Mar 24 at 21:09









      Gergő HorváthGergő Horváth

      628216




      628216






















          1 Answer
          1






          active

          oldest

          votes


















          0














          yes, I think this is related to the async nature of the Firebase design. So signInWithEmail... works, but it doesn't immediately reflect the change on the currentUser object. Instead, use the event onAuthStateChanged to do any code related to the currentUser. The process would be:



          1. Register the onAuthStateChanged event, and inside it detect for currentUser == null, this event will always get called on first definition with a null user, so by putting an if inside you can detect when you're dealing with an actual signIn.


          2. Add the signIn function, but don't do anything on the callback with the currentuser here, instead move the relevant code to onAuthStageChanged.


          Also, not 100% sure that you have to wrap the event inside a module and export it, or that you should. When doing web apps, each page is supposed to be state-less and independent, so each page should have its own script code to check for auth events and do whatever is appropriate.



          I do it like that and so far has worked all the time. Good luck!






          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%2f55328608%2fwhy-firebase-signinwithemailandpassword-doesnt-trigger-onauthchange%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














            yes, I think this is related to the async nature of the Firebase design. So signInWithEmail... works, but it doesn't immediately reflect the change on the currentUser object. Instead, use the event onAuthStateChanged to do any code related to the currentUser. The process would be:



            1. Register the onAuthStateChanged event, and inside it detect for currentUser == null, this event will always get called on first definition with a null user, so by putting an if inside you can detect when you're dealing with an actual signIn.


            2. Add the signIn function, but don't do anything on the callback with the currentuser here, instead move the relevant code to onAuthStageChanged.


            Also, not 100% sure that you have to wrap the event inside a module and export it, or that you should. When doing web apps, each page is supposed to be state-less and independent, so each page should have its own script code to check for auth events and do whatever is appropriate.



            I do it like that and so far has worked all the time. Good luck!






            share|improve this answer



























              0














              yes, I think this is related to the async nature of the Firebase design. So signInWithEmail... works, but it doesn't immediately reflect the change on the currentUser object. Instead, use the event onAuthStateChanged to do any code related to the currentUser. The process would be:



              1. Register the onAuthStateChanged event, and inside it detect for currentUser == null, this event will always get called on first definition with a null user, so by putting an if inside you can detect when you're dealing with an actual signIn.


              2. Add the signIn function, but don't do anything on the callback with the currentuser here, instead move the relevant code to onAuthStageChanged.


              Also, not 100% sure that you have to wrap the event inside a module and export it, or that you should. When doing web apps, each page is supposed to be state-less and independent, so each page should have its own script code to check for auth events and do whatever is appropriate.



              I do it like that and so far has worked all the time. Good luck!






              share|improve this answer

























                0












                0








                0







                yes, I think this is related to the async nature of the Firebase design. So signInWithEmail... works, but it doesn't immediately reflect the change on the currentUser object. Instead, use the event onAuthStateChanged to do any code related to the currentUser. The process would be:



                1. Register the onAuthStateChanged event, and inside it detect for currentUser == null, this event will always get called on first definition with a null user, so by putting an if inside you can detect when you're dealing with an actual signIn.


                2. Add the signIn function, but don't do anything on the callback with the currentuser here, instead move the relevant code to onAuthStageChanged.


                Also, not 100% sure that you have to wrap the event inside a module and export it, or that you should. When doing web apps, each page is supposed to be state-less and independent, so each page should have its own script code to check for auth events and do whatever is appropriate.



                I do it like that and so far has worked all the time. Good luck!






                share|improve this answer













                yes, I think this is related to the async nature of the Firebase design. So signInWithEmail... works, but it doesn't immediately reflect the change on the currentUser object. Instead, use the event onAuthStateChanged to do any code related to the currentUser. The process would be:



                1. Register the onAuthStateChanged event, and inside it detect for currentUser == null, this event will always get called on first definition with a null user, so by putting an if inside you can detect when you're dealing with an actual signIn.


                2. Add the signIn function, but don't do anything on the callback with the currentuser here, instead move the relevant code to onAuthStageChanged.


                Also, not 100% sure that you have to wrap the event inside a module and export it, or that you should. When doing web apps, each page is supposed to be state-less and independent, so each page should have its own script code to check for auth events and do whatever is appropriate.



                I do it like that and so far has worked all the time. Good luck!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 24 at 21:33









                Sergio FloresSergio Flores

                31017




                31017





























                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328608%2fwhy-firebase-signinwithemailandpassword-doesnt-trigger-onauthchange%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

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해