|
|
|
@@ -1,56 +0,0 @@ |
|
|
|
import * as firebase from 'firebase'; |
|
|
|
import { Router } from '@angular/router'; |
|
|
|
import { Injectable } from '@angular/core'; |
|
|
|
import { Store } from '@ngrx/store'; |
|
|
|
|
|
|
|
import * as fromApp from '../ngrx/app.reducers'; |
|
|
|
import * as AuthActions from './ngrx/auth.actions'; |
|
|
|
|
|
|
|
@Injectable() |
|
|
|
export class AuthService { |
|
|
|
constructor(private router: Router, private store: Store<fromApp.AppState>) {} |
|
|
|
|
|
|
|
signupUser(email: string, password: string) { |
|
|
|
firebase.auth().createUserWithEmailAndPassword(email, password) |
|
|
|
.then( |
|
|
|
user => { |
|
|
|
firebase.auth().currentUser.getIdToken() |
|
|
|
.then( |
|
|
|
(token: string) => { |
|
|
|
this.store.dispatch(new AuthActions.SetToken(token)); |
|
|
|
} |
|
|
|
); |
|
|
|
this.store.dispatch(new AuthActions.Signup()); |
|
|
|
this.router.navigate(['/']); |
|
|
|
} |
|
|
|
) |
|
|
|
.catch( |
|
|
|
error => console.log(error) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
signinUser(email: string, password: string) { |
|
|
|
firebase.auth().signInWithEmailAndPassword(email, password) |
|
|
|
.then( |
|
|
|
response => { |
|
|
|
firebase.auth().currentUser.getIdToken() |
|
|
|
.then( |
|
|
|
(token: string) => { |
|
|
|
this.store.dispatch(new AuthActions.SetToken(token)); |
|
|
|
} |
|
|
|
); |
|
|
|
this.store.dispatch(new AuthActions.Signin()); |
|
|
|
this.router.navigate(['/']); |
|
|
|
} |
|
|
|
) |
|
|
|
.catch( |
|
|
|
error => console.log(error) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
logout() { |
|
|
|
firebase.auth().signOut(); |
|
|
|
this.store.dispatch(new AuthActions.Logout()); |
|
|
|
this.router.navigate(['/']); |
|
|
|
} |
|
|
|
} |