首页 > 解决方案 > 离线时停止监听 AngularFireAuth

问题描述

在我的 Angular 应用程序上,我使用它来了解状态(来源:https ://medium.com/@balramchavan/detecting-internet-connection-status-in-angular-application-ng-connection-service-1fa8add3b975 )

constructor(private connectionService: ConnectionService) {
    this.connectionService.monitor().subscribe(isConnected => {
      if (isConnected) {
        // ONLINE
      }
      else {
        // OFFLINE
      }
    })
  }

对于我的 firebase 存储库,为了避免控制台错误泛滥,我有:

constructor(
    protected afs: AngularFirestore,
    protected connectionService: ConnectionService,
    protected collectionName: string,
  ) {
    this.connectionService.monitor().subscribe(status => {
      if (status) {
        afs.firestore.enableNetwork();
      }
      else {
        afs.firestore.disableNetwork();
      }
    })


  }

但我没有找到对 Auth Firebase 服务执行相同操作的方法:

constructor(
    private angularFireAuth: AngularFireAuth,
    protected connectionService: ConnectionService,
  ) {
    this.connectionService.monitor().subscribe(status => {
      if (status) {
        angularFireAuth.//Start listening
      }
      else {
        angularFireAuth.//Stop listening
      }
    })
  }

所以我多次收到此错误:

发布https://securetoken.googleapis.com/v1/token?key=XXX net:: ERR_INTERNET_DISCONNECTED

你知道怎么处理吗?

谢谢

标签: javascriptangularfirebase-authenticationangularfire2

解决方案


推荐阅读