Angularfire: Delete Logged in User

Created on 9 Jul 2016  路  8Comments  路  Source: angular/angularfire

Hi,

I want to know how we are going to delete the logged in user like this firebase sdk api. https://firebase.google.com/docs/reference/js/firebase.User#delete

RFC / discussion / question

Most helpful comment

For those using this snippet, this will always give a console.error because the auth will emit a null after delete(), and the subscription does not terminate which will delete any other user that tries to login.

Taking only the first value solves this:

    af.auth
      .first()
      .subscribe(authState => {
        console.log(authState);
        authState.auth.delete()
          .then(_ => console.log('deleted!'))
          .catch(e => console.error(e))
      });

All 8 comments

This is definitely a design issue. We scrub over the firebase.User type and we lose the functionality. @jeffbcross We need to consider firebase.User methods when converting to FirebaseAuthState.

Are there implemented or planned any functionality for an admin to rapidly delete registered auth-users? I would really like admins to have that possibility from my application.

@hopeeen Great question. Please submit your own issue rather than diluting tangentially related topics. I'd be happy to answer this, but not here.

@smkamranqadri You can actually delete this user using the result of the AuthState.

constructor(af: AngularFire) {
  af.auth.subscribe(authState => {
     authState.auth.delete()
        .then(_ => console.log('deleted!'));
        .catch(e => console.error(e));
  });
}

I'm going to close this issue because we need a better design to accommodate the underlying firebase.User object.

Well thanks a lot for the solution.

For those using this snippet, this will always give a console.error because the auth will emit a null after delete(), and the subscription does not terminate which will delete any other user that tries to login.

Taking only the first value solves this:

    af.auth
      .first()
      .subscribe(authState => {
        console.log(authState);
        authState.auth.delete()
          .then(_ => console.log('deleted!'))
          .catch(e => console.error(e))
      });

@davideast using AF 5.0.0-rc.5-next you have to add first() so it would become

this.afAuth.authState.first().subscribe((authState) => { authState.delete(); }); where afAuth is private afAuth: AngularFireAuth

Thanks @ix-xerri and @nunojpg .
The delete works like a charm :)
But how about the open subscriptions that I have for that user I deleted?
I'me getting "permission_denied" on all open subscriptions :(
Thanks.

Was this page helpful?
0 / 5 - 0 ratings