Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- loginUser() {
- if(this.username == 'test' && this.password == 'test'){
- this.service.login().subscribe(userIsLoggedIn =>
- this.router.navigate(['admin/overview']));
- }
- }
- {
- path: 'admin',
- component: AdminLoginComponent,
- data: {title: 'Admin'}
- },
- {
- path: 'admin/overview',
- component: AdminOverviewComponent,
- canActivate: [AuthGuard],
- data: {title: 'Overview'}
- }
- @Injectable()
- export class AuthService {
- user: Observable<firebase.User>;
- constructor(private firebaseAuth: AngularFireAuth){
- this.user = firebaseAuth.authState;
- }
- isLoggedIn = false;
- login(email: string, password: string): Observable<boolean> {
- this.firebaseAuth
- .auth
- .signInWithEmailAndPassword(email, password)
- .then(value => {
- return Observable.of(true).delay(1000).do(val => this.isLoggedIn = true);
- })
- .catch(err => {
- console.log('Something went wrong:',err.message);
- });
- return Observable.of(false).delay(1000).do(val => this.isLoggedIn = false);
- }
- }
- constructor(private router: Router, private service: AuthService){}
- loginUser() {
- this.service.login(this.email, this.password).subscribe(userIsLoggedIn =>
- this.router.navigate(['admin/overview']));
- this.email = this.password = '';
- console.log('test');
- }
Add Comment
Please, Sign In to add comment