Search code examples
angulartypescriptionic-frameworkapp-startupbaqend

BaQend - DBready at initializing, check login status of user


I'm working with BaQend & Ionic2 and try to get some task at App-start.

1. DBready

I don't want to do this at every single page:

ionViewCanEnter(): Promise<baqend> {
        // Check if the Baqend SDK is ready and wait for initialization
        return this.ready.resolve().then(db => this.db = db);
}

I tried this, but it isn't working:

initializeApp() {
        this.platform.ready().then(() => {
          // Okay, so the platform is ready and our plugins are available.
          // Here you can do any higher level native things you might need.
          this.statusBar.styleDefault();
          this.splashScreen.hide();
          return this.ready.resolve().then(db => this.db = db);
        });
      }

2. Check users login status

On App start, i should check the login status of the user and if he/she isn't signed in, it should open the LoginModal.

ionViewWillEnter(){
    if (this.db.User.me) {
      console.log(this.db.User.me.username,' entered HomePage with ID ', this.db.User.me.id);
    } else {
      this.openLoginModal()
      console.log('Hello Anonymous');
    }
  }

This is a working code for the rootPage, but it would be better to get this into app startup.

Any ideas?


Solution

  • Very good point,

    we have updated our ionic starter. We moved the DBReady check to the root view. In our starter that is the tabs.component.ts. The Rootview then always waits on the db, before it renders the child views.

    If you update the db.service.ts as well, you can also use the db exported from the SDK now.

    import { db } from "baqend";