码迷,mamicode.com
首页 > 其他好文 > 详细

[AngularFire2] Auth with Firebase auth -- email

时间:2016-11-20 07:20:14      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:eth   value   any   first   mail   because   router   --   complete   

First, you need to enable the email auth in Firebase console.

 

Then implement the auth service:

  login(email, password) {

    return this.fromFirebaseAuthPromise(this.auth$.login({
      email, password
    },{
      method: AuthMethods.Password,
      provider: AuthProviders.Password
    }));
  }

  fromFirebaseAuthPromise(promise) {
    const subject = new Subject<any>();

    promise.then((res) => {
      subject.next(res);
      subject.complete();
    }, err => {
      subject.error(err);
      subject.complete();
    });

    return subject.asObservable();
  }

Because login method return Promise, we need to convert it to Observable. The way we do it is using ‘subject‘.

 

Controller:

  login(){
    const formValue = this.form.value;

    this.authService.login(formValue.email, formValue.password)
      .subscribe((res) => {
         this.router.navigate([/home]);
      })
  }

 

[AngularFire2] Auth with Firebase auth -- email

标签:eth   value   any   first   mail   because   router   --   complete   

原文地址:http://www.cnblogs.com/Answer1215/p/6082053.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!