【发布时间】:2018-08-30 11:09:08
【问题描述】:
我在一个项目中使用 Firebase + Ionic。注销时出现我的问题。我订阅了一些集合中的几个onSnapshot 事件。我希望每当用户注销时所有订阅都会被取消,但事实并非如此,所以每当我注销时,我都会收到来自 Firebase 的几个错误:
onSnapshot 中未捕获的错误:错误:缺失或不足 权限。
这是我的代码:
我的控制器
/**
* Logout button 'click' event handler
*/
onLogoutPressed(){
this.fbAuthServ.logout().then(() => {
this.navCtrl.setRoot(LoginPage);
});
}
我的服务商
// Firebase Modules
import { AngularFireAuth } from 'angularfire2/auth';
constructor(private afAuth: AngularFireAuth, private utils: UtilsProvider){}
...
/**
* Firebase Logout the current user
*/
async logout(){
this.afAuth.auth.signOut();
}
您能告诉我应该怎么做才能避免那些Missing or insufficient permissions 错误吗??
提前谢谢你!
编辑:我如何订阅 onSnapshot 事件
控制器
ionViewDidEnter(){
this.fbDataServ.getPlacesByUserAllowed().onSnapshot(placeReceived=> {
this.placesByUserAllowed = placeReceived.docs.map(placeSnapshot => {
return this.utils.mapPlaceSnapshot(placeSnapshot )
});
this._concatPlaces();
//Dismiss loading whenever we have data available
this.utils.dismissLoading();
});
服务提供者
// Firebase
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
constructor(private afs: AngularFirestore, private fbAuthServ: FirebaseAuthServiceProvider, private utils: UtilsProvider) { }
placesCollection: AngularFirestoreCollection<PlaceModel> = this.afs.collection("places");
/**
* Gets the collection of places where the user is 'allowed'
*/
public getPlacesByUserAllowed(){
return this.placesCollection.ref
.where('users.' + this.fbAuthServ.getCurrentUser().uid + '.allowed', '==', true);
}
【问题讨论】:
标签: javascript firebase ionic-framework firebase-authentication angularfire2