Guest User

Untitled

a guest
Jan 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. onLoginEmail(): void {
  2. if (this.validateForm(this.email, this.password)) {
  3. this.authService.loginWithEmail(this.email, this.password)
  4. .then(() => this.router.navigate(['/home']))
  5. .catch(_error => {
  6. this.error = _error
  7. this.router.navigate(['/'])
  8. })
  9. }
  10.  
  11. loginWithEmail(email: string, password: string) {
  12. return this.afAuth.auth.signInWithEmailAndPassword(email, password)
  13. .then((user) => {
  14. this.authState = user
  15. this.isLoggedIn()
  16. })
  17. .catch(error => {
  18. console.log(error)
  19. throw error
  20. });
  21.  
  22. isLoggedIn() {
  23. this.afAuth.auth.onAuthStateChanged(auth => {
  24. if (auth) {
  25. console.log(auth);
  26. } else {
  27. console.log('User logged out');
  28. }
  29. });
  30. }
Add Comment
Please, Sign In to add comment