Angularfire: [Authentication] Weird behavior !?

Created on 6 Aug 2016  路  14Comments  路  Source: angular/angularfire

Hi,

I was playing around with the Auth service, and I discovered a weird behavior...

Most of the time, when trying to log in using any provider (see screenshot), I always receive two streams values:

  1. The first one contains the correct auth info;
  2. A second one with a null value!! (which means that the user is not logged in).

image

However, after refreshing the app (i.e. hitting F5), I get one event back with the right session info:

image

And, when logging out, the app receives a null value, which is the expected behavior ofc:

image

Here is a portion of my code:

    this.af.auth.subscribe(
      user => {
        if(user) {
          this.isAuth = true;
        }
        else {
          this.isAuth = false;
        }
      },
      error => {
        console.trace(error);
      }
    );

Any idea?

bug

Most helpful comment

Sorry for the delay @manekinekko! Thank you for your hard work on this issue! We will get it fixed for the next release :)

All 14 comments

After some trials. It seems that this behavior only happens when using the AuthMethods.Redirect method.

Can you throw up an example on plnkr so I can debug the heck out of it?

@davideast I'll set up a plnkr for you. In the mean time, the code lives here: https://github.com/manekinekko/angular2-firebase-authentication
And of course, the bootstrap configuration: https://github.com/manekinekko/angular2-firebase-authentication/blob/master/src/main.ts#L25
You just need to use the AuthMethods.Redirect method

@davideast here is the plnkr: https://plnkr.co/edit/qA6ebLo4ISfK5og28m71?p=preview (you need to open the app in live mode so the redirect can work).

I added a log output. As you can see, when login in using a redirect method, we have 2 entries in the output json logs array:

  • the first entry contains the session info
  • a second entry with a NULL value

image

I've tracked down this issue. And here is what I found: it seems that both statements get executed:

  1. L58: executes first and return the correct session state
  2. L53: executes next and returns NULL

image

Sorry for the delay @manekinekko! Thank you for your hard work on this issue! We will get it fixed for the next release :)

@davideast, looks like this will solve #324 as well. Should we mark that one as duplicate as well, like #452?

I did for one of them, but yes it should be for both.

@davideast I just updated my app to angularfire2@next and the issue seems to be fixed 馃憦
Here is my commit: https://github.com/manekinekko/angular2-firebase-authentication/commit/64066bb66c3e67865a4f64d1560ddd59483a6a5a
(btw, I had to upgrade angular2 to RC5 too, hence all those changes)

@manekinekko What is your version of angularfire2 after the update?

@vkniazeu I was using angularfire2@next.

@manekinekko Just to be sure, do you have 2.0.0-beta.4?
I see this one as the latest. What does your npm list show after running angularfire2@next for angularfire2? Thanks!

Nope. I updated my code before beta4 ^^
It listed beta3.pre-2. See here https://github.com/manekinekko/angular2-firebase-authentication/commit/64066bb66c3e67865a4f64d1560ddd59483a6a5a#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R28

@davideast AuthMethods.Redirect is working for me now too after the update to 2.0.0-beta.4.
Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adriandurran picture adriandurran  路  3Comments

jteplitz picture jteplitz  路  3Comments

avanderbergh picture avanderbergh  路  3Comments

fisherds picture fisherds  路  3Comments

itisparas picture itisparas  路  3Comments