【发布时间】:2017-10-09 20:46:19
【问题描述】:
我有一个使用 angularfire2 和 firebase 的 ionic3 应用程序。我使用 firbase auth 登录到我的应用程序,并从 firebase 检索有关“currentChallenges”的对象。当我使用注销功能时,Firebase 会引发错误。
错误信息:
permission_denied at /currentChallenge:客户端没有权限 访问所需的数据。
我在 auth.service.ts 中使用以下函数进行注销:
logout() {
this.isLoggedIn = false;
this.firebaseAuth
.auth
.signOut().then(() => {
this.appCtrl.getRootNav().popToRoot(); //root is login page
});
}
我不确定到底是哪里/是什么导致了错误。在我的challenge.service.ts 中,我制作了初始可观察对象:
private dbCurrentChallengesObservable: FirebaseObjectObservable <any>;
constructor(db: AngularFireDatabase) {
this.dbCurrentChallengesObservable = db.object('/currentChallenge');
}
public getCurrentChallenges(){
return this.dbCurrentChallengesObservable;
}
然后,我在我的模型 (challenges.ts) 中使用这个对象,如下所示:
ionViewCanEnter(): boolean{
return this.authService.isAuthenticated();
}
ionViewDidLoad() {
this.currentChallenge = this.challengesService.getCurrentChallenges();
this.currentChallenge.subscribe(data => {
if(data.challenge1completed > 0) this.challenge1Completed = true;
if(data.challenge2completed > 0) this.challenge2Completed = true;
});
}
起初我以为它与订阅有关,我在 Challenges.ts 的 on-ion-leave 函数中添加了一个 subscribe().unsubscribe(),但这并没有阻止错误。但是某些东西必须仍然在听firebase,必须在注销时甚至注销之前停止。我只是不知道什么/在哪里/如何。
任何帮助将不胜感激。
【问题讨论】:
标签: firebase firebase-authentication ionic3 angularfire2