Skip to content

Instantly share code, notes, and snippets.

@tobinbc
Last active August 4, 2019 16:54
Show Gist options
  • Save tobinbc/8a3af16f7bbde0ee973056bd8d8178ee to your computer and use it in GitHub Desktop.
Save tobinbc/8a3af16f7bbde0ee973056bd8d8178ee to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { Events, NavController, Platform } from '@ionic/angular';
import { AmplifyService } from 'aws-amplify-angular';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']
})
export class AppComponent {
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private amplifyService: AmplifyService,
private navCtrl: NavController,
private events: Events,
) {
this.initializeApp();
this.amplifyService.authStateChange$.subscribe(authState => {
switch (authState.state) {
case 'signedOut':
this.navCtrl.navigateRoot('unauthorised')
this.events.publish('loggedIn', false)
break;
case 'signedIn':
this.events.publish('loggedIn', true)
this.navCtrl.navigateRoot('authourised')
breaks
}
})
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide(); //Or wait until authState has been determined to hide the splashscreen
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment