angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.67k stars 2.19k forks source link

docs(auth): Add to developer guide approaches to managing authentication state #343

Closed jek-bao-choo closed 3 years ago

jek-bao-choo commented 8 years ago

How to manage AngularFire2 authentication state (emit observable of sign-in or logout status) and Angular2 (RC4 and above) route guard to work with angularfire2?

I asked a question in Stackoverflow. But I feel that a detailed documentation here would benefit AngularFire2 Community.

samirthebti commented 8 years ago

Yes we need a detailed documentation for use AngularFire .

davideast commented 8 years ago

Agreed! We will be expanding our docs in a future release.

jek-bao-choo commented 8 years ago

It would be good if AngularFire2 documentation could include detailed explanation on this

AngularFire2 has a af.auth.subscribe() to subscribe to the auth service. The question is how can i make the guard wait for the observable and then return either true or false?

From reddit.com/r/Angular2/comments/4trb3v/how_to_implement_guard_with_angularfire2/

jek-bao-choo commented 8 years ago

Hi @davideast I can lend a hand if you need me. You could put together an application for this purpose. I'll use that application that you put together to enhance the existing markdown documentation. Hope this would be helpful.

bogacg commented 7 years ago

Is there any progress in this front. I've tried same approach in my app, with similar auth-service of todo-angular2-firebase example, having auth-guard and unauth-guard. When I logout, canActivate gets called always prior to auth object nulls. I've tried .take(1) or .first()...no luck. Why .logout() does not return promise anyways?

UPDATE: In my Auth-service signout() method I directly use firebase.auth().signOut().then(... now, instead of FirebaseAuthState's .logout() method since firebase.auth().signOut() returns a promise. I hope this doesn't break anything else.

jeremyputeaux commented 7 years ago

Is there any progress on this ?

rashnk commented 7 years ago

AngularFire vs AngularFireAuth , both returns the same result , so AngularFire will handle all opereation it seems

constructor(public auth$: AngularFireAuth, public navCtrl: NavController, public af: AngularFire) {

    this.authState = auth$.getAuth();
    auth$.subscribe((state: FirebaseAuthState) => {
      this.authState = state;
      console.log(state);
    });
    //af.auth.getAuth()
    this.af.auth.subscribe(auth => {
      console.log(auth)

    });// user info is inside auth object
  }
jamesdaniels commented 3 years ago

Closing as outdated, we've revamped all of our auth handling have guards, etc. now all fairly well documented.