首页 > 代码库 > [AngularFire2] Auth with Firebase auth -- email
[AngularFire2] Auth with Firebase auth -- email
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 = http://www.mamicode.com/this.form.value; this.authService.login(formValue.email, formValue.password) .subscribe((res) => { this.router.navigate([‘/home‘]); }) }
[AngularFire2] Auth with Firebase auth -- email
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。