我有一个使用 angularfire2 和 firebase 的 ionic3 应用程序。我使用 firbase auth 登录我的应用程序,并从 firebase 检索有关“currentChallenges”的对象。当我使用注销功能时,Firebase 会引发错误。
错误消息:
permission_denied at /currentChallenge: Client doesn't have permission to access the desired data.
我在 auth.service.ts 中使用以下函数进行注销:
logout() {
this.isLoggedIn = false;
this.firebaseAuth
.auth
.signOut().then(() => {
this.appCtrl.getRootNav().popToRoot(); //root is login page
});
}
我不确定到底是在哪里/什么原因导致了错误。在我的 Challenges.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,必须在注销时甚至注销之前停止。我只是不知道什么/在哪里/如何。
如有任何帮助,我们将不胜感激。
最佳答案
private afDatabase: AngularFireDatabase,//blabla
this.afDatabase.database.goOffline();//To solve the permission denied 문제.
在signout()之前添加上述语句;
我也花了很多时间来解决这个问题,但没有找到任何线索。 希望这有帮助
关于firebase - 身份验证注销时出现权限错误 : firebase/ionic/angularfire2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46654706/