【发布时间】:2017-01-23 10:35:13
【问题描述】:
我正在使用 Firebase 和 AngularFire2 库构建一个 Angular2 应用程序。
在建立授权连接后用户注销时如何处理?例如,具有有效帐户的用户登录,连接到我的 Firebase 数据库的“订单”节点,然后用户注销。
我在控制台中收到以下错误,这很有意义。但是我应该如何捕捉这个错误或以其他方式防止它呢?
错误:
FIREBASE WARNING: Exception was thrown by user callback. Error: permission_denied at /orders: Client doesn't have permission to access the desired data.
相关代码(我认为):
@Injectable()
export class OrderService {
private orders$: FirebaseListObservable<any>;
private _pendingOrders$: BehaviorSubject<any> = new BehaviorSubject(null);
private _activeOrders$: BehaviorSubject<any> = new BehaviorSubject(null);
constructor(
private af: AngularFire,
private auth: AuthService) {
this.auth.isAuthed
.subscribe((value: boolean) => {
if (this.auth.isAuthed.value) {
const userId = this.auth.getUserId();
this._subscribeToUserOrders(userId);
} else {
// Somehow unsubscribe here, perhaps?
}
});
}
_subscribeToUserOrders(userId) {
const query = {
orderByChild: 'userId',
equalTo: userId
};
this.orders$ = this.af.database
.list(`orders`, query);
this.orders$.subscribe((orders) => {
// Load pending orders
this._pendingOrders$.next(orders.filter(o => o.status === 'PENDING'));
// Load active orders
this._activeOrders$.next(orders.filter(o => o.status === 'ACTIVE'));
});
}
get pendingOrders() {
return this._pendingOrders$.asObservable();
}
get activeOrders() {
return this._activeOrders$.asObservable();
}
}
【问题讨论】:
标签: angular firebase firebase-realtime-database angularfire2