0
votes

I am trying to write a signout method.Before signing out im trying to unsubscribe my previous subscribtions otherwise i get many subscribe and permission errors

this is signout method(button click triggers this)

console.log(this.profileData);
this.profileData.unsubscribe();

  this.app.auth().signOut().then(function() {

    alert("you successfully signed out");

  }, function(error) {
  alert("error");
  });

this is how i subscribe

    this.profileData = this.fire.authState.switchMap(auth => this.db.object(`profile/${auth.uid}`).valueChanges());
  this.profileData.subscribe(profile =>{...

enter image description here

2
this question is still active - Yunus Emre Guney Student

2 Answers

1
votes

unsubscribe is interface for subscription, which returned by this.profileData.subscribe(...). It seems currently this.profileData is assigned to Observable instead.

0
votes

You are trying to unsubscribe an observable, not a subscription. You should do this instead:

this.profileData = this.fire.authState.switchMap(auth => this.db.object(`profile/${auth.uid}`).valueChanges());
this.profileSubcription = this.profileData.subscribe(profile =>{...});

console.log(this.profileData);
this.profileSubcription.unsubscribe();

this.app.auth().signOut().then(function() {

 alert("you successfully signed out");

}, function(error) {
 alert("error");
});