Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AngularFireAuth.authState does not fire #2309

Closed
sarunint opened this issue Feb 3, 2020 · 18 comments
Closed

AngularFireAuth.authState does not fire #2309

sarunint opened this issue Feb 3, 2020 · 18 comments

Comments

@sarunint
Copy link
Contributor

sarunint commented Feb 3, 2020

Version info

Angular: 8.2.14

Firebase: 7.8.0

AngularFire: 5.4.0-5.4.1

Other (e.g. Ionic/Cordova, Node, browser, operating system):

How to reproduce these conditions

Failing test unit, Plunkr, or JSFiddle demonstrating the problem: https://stackblitz.com/edit/angular-lgfgbl

Steps to set up and reproduce

  1. Fill your Firebase config in app.module.ts
  2. Run
  3. Click "Sign in with Google"

Sample data and security rules: none

Debug output

** Errors in the JavaScript console **: none

** Output from firebase.database().enableLogging(true); **: not applicable

** Screenshots **

Expected behavior

After redirected back from sign-in, you should be automatically to /main path.

Actual behavior

The app does not redirect you to /main path. (It does in @angular/fire@5.3.1.)

My observation

If I remove the line this.user$ = this.afa.authState; out from app.component.ts, it works! Doesn't know why.

@techn1fire
Copy link

Same issue here. Seems to fire randomly, or after a few seconds during testing.

@JoshuvaGeorge03
Copy link

I do having this issue, how to fix this?

@FlexWilliams
Copy link

Seeing same issue with the authState observable not being fired when subscribed to.

Just upgraded:
firebase 6.5.0 to 7.8.0
@angular/fire 5.2.1 to 5.4.0

@Benny739
Copy link

Benny739 commented Feb 5, 2020

Same issue here.

@alexregier
Copy link

Same here :D

@jamesdaniels
Copy link
Member

Should be addressed in 5.4.1, sorry for the regression. Please reopen if you're still having trouble after upgrading.

@sarunint
Copy link
Contributor Author

sarunint commented Feb 6, 2020

It does not fix this 😉. That's the reason why this issue and #2307 are separated.

@sarunint
Copy link
Contributor Author

sarunint commented Feb 6, 2020

@jamesdaniels It seems that I can't reopen this issue. Lol

@sarunint
Copy link
Contributor Author

sarunint commented Feb 6, 2020

I've been able to create a simpler reproduction here: https://stackblitz.com/edit/angular-bk3qb6

@jamesdaniels jamesdaniels reopened this Feb 6, 2020
@sarunint
Copy link
Contributor Author

sarunint commented Feb 6, 2020

I've also noticed that changing to .user solves the problem.

But, if you change both .authState to .user, the problem still exists.

image

I think this is may be due to how both fields is constructed.

this.authState = new Observable<User | null>(subscriber => {
return zone.runOutsideAngular(() => this.auth.onAuthStateChanged(subscriber));
}).pipe(keepUnstableUntilFirst);;
this.user = new Observable<User | null>(subscriber => {
return zone.runOutsideAngular(() => this.auth.onIdTokenChanged(subscriber));
}).pipe(keepUnstableUntilFirst);

I'm thinking ReplaySubject might work here...

@jamesdaniels
Copy link
Member

jamesdaniels commented Feb 6, 2020

Just killed my last comment since I've found the root cause and I was going down the wrong path. It seems something about the new Zone refactors is breaking multiplexing.

@jamesdaniels
Copy link
Member

It seems to be forcing a share, where one shouldn't exist, even if you use a different factory. This came up in review but I thought it was addressed.

@jamesdaniels
Copy link
Member

jamesdaniels commented Feb 6, 2020

Since it's shared without replay, the second subscribe gets no result until a change comes through; since it's not creating a new observable. If I don't have a fix quickly I'll revert the zone memory leaks in a patch. Thanks so much for catching this!

@jamesdaniels
Copy link
Member

jamesdaniels commented Feb 6, 2020

@JoshuvaGeorge03
Copy link

This issue still present in 5.4.1 also.

@jamesdaniels
Copy link
Member

Fixed in 5.4.2

@FlexWilliams
Copy link

FlexWilliams commented Feb 6, 2020

Updated to 5.4.2, looks fixed on my end, running:

"@angular/fire": "^5.4.2",
"firebase": "^7.8.0"

Thanks for the quick fix!

@ckrandhir
Copy link

I think it not working in "@angular/fire": "^6.0.0". Could you please look into this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants