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

Getting user data with async after page refresh takes long time #231

Closed
orangesoup opened this issue Jun 17, 2016 · 6 comments
Closed

Getting user data with async after page refresh takes long time #231

orangesoup opened this issue Jun 17, 2016 · 6 comments
Assignees
Milestone

Comments

@orangesoup
Copy link

I couldn't make a plunker, so I'm just gonna try to explain here. - I'm using SDK 3.0.

I have a simple Password auth (just an example, probably doesn't matter which one).

this.af.auth.login({ email, password }, {
  provider: AuthProviders.Password,
  method: AuthMethods.Password
});

Works fine, user can log in, data gets stored in localStorage, everything is shiny. However, when I refresh the page it takes almost 10 seconds to show the user data when using asyncpipe.

constructor(public _auth: FirebaseAuth, ...) { ... }
<div> {{ (_auth | async)?.uid }} </div>

Everything is loaded, I mean literally everything, and then after 8-10 seconds the uid just shows up. If I click the login button while waiting to uid to show up (so at this moment I have my data in localStorage already), the uid shows up instantly (it still makes a login request, but the uid shows up before that request actually finishes).

Honestly, I'm not sure if I'm doing something wrong here and this is an intended behavior (in this case please point me to the right direction), but it's really bad UX.


Not sure if it matters, but my main goal would be to show the users email address if they're logged in, but it's kinda weird when the page loads it shows nothing for ~10 seconds and then just suddenly pops out.

@Zyzle
Copy link

Zyzle commented Jun 17, 2016

I've noticed this as well with the switch to beta1 and the 3.0 firebase sdk. By the sound of things I'm doing something similar to you only using Google authentication. There seems to be a fairly major downgrade in the time it takes to retrieve the auth information from firebase compared to the 2.x version. All other database interactions seem unaffected.

@orangesoup
Copy link
Author

The interesting thing is if you subscribe to auth

this.af.auth.subscribe(auth => console.log(auth));

It logs the data pretty fast, there's no waiting there (at least for me). It seems like it's just the view that's affected (?)

@jeffbcross
Copy link
Contributor

Hmm, from @orangesoup 's description, it sounds like the Angular zone isn't picking up the change. I will look into this this afternoon.

@jeffbcross jeffbcross self-assigned this Jun 17, 2016
@jeffbcross jeffbcross added this to the beta.2 milestone Jun 17, 2016
@orangesoup
Copy link
Author

orangesoup commented Jun 20, 2016

@jeffbcross I'm not sure whether it's a bug or not, so I'm asking here first and if it is I can open a new issue:

I've been debugging my app when I tried out a weird scenario: I have an AuthService and in its constructor I'm subscribing to auth and saving the user data into a variable each time it changes. When I manually delete the firebase:authUser:... object from localStorage I get null in the subscription, but when I log in again I get nothing, no event (I'm not sure how it's called in observables land?) fired. Obviously I can take the new user object from the logins promise, but shouldn't I get the object in the subscription as well?

Edit: since I'm not sure how all this works under the good I've tried out using the proper logout() function, but the result is the same. When logging out I get a null object, but when I log in again I get nothing.

@jeffbcross
Copy link
Contributor

@orangesoup that does sound like a bug; a new issue would be appreciated! There is definitely some complexity in the onAuth pipeline right now to try to have some consistent behavior with the old API.

jeffbcross added a commit to jeffbcross/angularfire2 that referenced this issue Jun 21, 2016
There is one place in auth that takes a promise from Firebase,
the promise from getRedirectResult(), and creates an observable
from it. Since Firebase is using their own Promise implementation,
the Promise and its derived observable were running in the root 
zone instead of the Angular zone, causing onAuth changes to not
immediately be propagated to the view. By casting the firebase
Promise to a zone-patched Promise, the observable now runs
in the Angular zone.

Fixes angular#231
@orangesoup
Copy link
Author

Alright, opened a new issue! Thanks for looking at it!

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

No branches or pull requests

3 participants