angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.64k stars 2.2k forks source link

Error Connection Time Out when connecting to Firebase Database #2262

Closed kalimulhaq closed 3 years ago

kalimulhaq commented 4 years ago

I'm use the Firebase in my Angular App for user Online/Offline Status two days before it was working but now suddenly it give error ERR_CONNECTION_TIMED_OUT firebase_connection_error

My Code Is

public startTimeTracking() {
    let user = this.profile;
    this.FireAuth.auth.signInWithEmailAndPassword(user.email, user.email).then(resp => {

      let uid = this.FireAuth.auth.currentUser.uid;
      let uEmail = this.FireAuth.auth.currentUser.email;
      let userStatusDatabaseRef = this.FireDatabase.database.ref('/status/' + uid);

      let isOfflineForDatabase = {
        state: 'offline',
        email: uEmail,
        offlineAt: new Date().getTime(),
      };

      let isOnlineForDatabase = {
        state: 'online',
        email: uEmail,
        // onlineAt: new Date().getTime(),
        offlineAt: new Date().getTime()
      };

      this.FireDatabase.database.ref('.info/connected').on('value', (snapshot) => {

        if (snapshot.val() == false) {
          return;
        }

        userStatusDatabaseRef.onDisconnect().set(isOfflineForDatabase).then(() => {
          userStatusDatabaseRef.set(isOnlineForDatabase).then(() => {
          });
        });
      });

      this.FireDatabase.database.ref('/status/').on('value', (snapshot: any) => {
      });

    }).catch((error: any) => {
      console.log(error);
      if (error.code === 'auth/user-not-found') {
        // Register use If user not found
        this.FireAuth.auth.createUserWithEmailAndPassword(user.email, user.email).then(resp => {
          this.startTimeTracking();
        });
      }
    });
  }

Version info

Angular: 6.0.0

Firebase: 5.5.5

AngularFire: 5.1.3

orimdominic commented 4 years ago

I'm having this issue too, but on a vanillaJS app.

jaytees commented 3 years ago

I am having the same issue.

Using RTDB with FS and Cloud Functions to manage user presence as suggested in the docs and periodically at no consistent interval. The FS status is changed to offline and I have the same errors in the console.

The unexplainable part is that the RTDB status is still set to online.

Did either of you get anywhere with this issue?

jamesdaniels commented 3 years ago

Not AngularFire specific, please open issue with the Firebase JS SDK if still encountering.