Last active
August 4, 2019 16:54
-
-
Save tobinbc/8a3af16f7bbde0ee973056bd8d8178ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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