IonicDB invalid handshake

(USING IONIC SERVE IN BROWSER) When a user signs up on my app, a connection to the database is created, and some preliminary data is inserted with their ID. This works fine. The problem comes if you log out and then sign up again, when it tries to connect again it says:

"Connection Failed:  Invalid handshake."

If I log out and refresh the app, and then sign up then it works ok. I’m thinking that something in the Auth or Database providers is holding a value from before the logout which is why the connection is failing on the new user. I had a look at local storage in chrome dev, and everything apart from “ionic_insights_session” is cleared when I log out. So I don’t know what the problem is. A few code snippets for you:

When a user signs up:

this.auth.signup(details).then(reply => {
    this.auth.login('basic', details).then(() => {
      this.db.connect();
      this.doneLoading();
      this.navCtrl.setRoot(GuidePage, {'justSignedUp': true}, {'animate': true, 'direction': 'forward'})
    }, err => {
      this.doneLoading();
      this.showErrPopup("Check your internet connection");
    });
}

this sends them to the guide page where:

ionViewDidLoad() {
  if (this.navParams.data.justSignedUp) {
    var points = this.db.collection("points");
    points.insert({
      id: this.user.id,
      points: 9000
    });
  }
}

And finally logout:

logout() {
  this.auth.logout();
  this.db.disconnect();
  this.navCtrl.setRoot(StartPage, null, {'animate': true, 'direction': 'back'});
}

As stated before, If I logout and then refresh the browser, it works fine. Any help would be great
Cheers

1 Like

I am facing the same issue.

This problem can be easily reproduced by two buttons:

this.db.connect()
this.db.disconnect()

If you connect() first and disconnect(), you won’t be able to connect() again. Tested in both safari and chrome. Really need help here.

I´ve got the same problem, i use window.location.reload(); but i think thats not a solution.

same here, I tried to automatically reconnect it when status changes, but it wont reconnect