Created
May 24, 2019 08:28
Ionic 4 Twitter Auth with Firebase - Auto-login
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 { Platform } from '@ionic/angular'; | |
import { SplashScreen } from '@ionic-native/splash-screen/ngx'; | |
import { StatusBar } from '@ionic-native/status-bar/ngx'; | |
import { Router } from '@angular/router'; | |
import { AngularFireAuth } from '@angular/fire/auth'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: 'app.component.html' | |
}) | |
export class AppComponent { | |
constructor( | |
private platform: Platform, | |
private splashScreen: SplashScreen, | |
private statusBar: StatusBar, | |
private router: Router, | |
private fireAuth: AngularFireAuth | |
) { | |
this.initializeApp(); | |
} | |
initializeApp() { | |
this.platform.ready().then(() => { | |
this.fireAuth.auth.onAuthStateChanged(user => { | |
if (user) { | |
this.router.navigate(["/profile"]); | |
this.splashScreen.hide(); | |
} | |
else { | |
this.router.navigate(["/home"]); | |
this.splashScreen.hide(); | |
} | |
}) | |
this.statusBar.styleDefault(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment