angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

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

Open jek-bao-choo opened this issue 10 years ago • 8 comments

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.

jek-bao-choo avatar Jul 10 '16 03:07 jek-bao-choo

Yes we need a detailed documentation for use AngularFire .

samirthebti avatar Jul 10 '16 23:07 samirthebti

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

davideast avatar Jul 15 '16 18:07 davideast

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 avatar Jul 21 '16 01:07 jek-bao-choo

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.

jek-bao-choo avatar Sep 01 '16 10:09 jek-bao-choo

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.

bogacg avatar Sep 28 '16 08:09 bogacg

Is there any progress on this ?

jeremyputeaux avatar Nov 11 '16 16:11 jeremyputeaux

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
  }

rashnk avatar Mar 23 '17 14:03 rashnk

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

jamesdaniels avatar Nov 18 '20 17:11 jamesdaniels