I want to implement a reset password / forgot password function with AngularFire2. It seems like the function sendPasswordResetEmail is not yet provided by AngularFire2 or the typings are not updated. Since sendPasswordResetEmail is part of AngularFireAuth, I thought I still could access the function like this:
(this.af.auth as any).sendPasswordResetEmail('email').
then((result: any) => {
console.log('Result:', result);
}).catch((err: any) => {
console.log('Err:', err);
});
Typescript gives me this error:
error TS2349: Cannot invoke an expression whose type lacks a call signature.
Since I am new to typescript + angular2, any hints how I can access the sendPasswordResetEmail ?. My guess is that I have to access the pure js sdk provided by firebase, but I dont know how.
Thanks.
AngularFireAuth. user provides you an Observable<User|null> to monitor your application's authentication State. AngularFireAuth promise proxies an initialized firebase. auth. Auth instance, allowing you to log users in, out, etc.
You may be able to use the existing but not fully implemented functionalities of AngularFire2 SDK by Injecting FirebaseApp
in your component constructor as seen below. This will give you access to the sendPasswordResetEmail
method:
import { Component, Inject } from '@angular/core';
import { AngularFire, FirebaseApp } from 'angularfire2';
@Component({
selector: 'app-forgot-password',
template: '...'
})
export class ForgotPasswordComponent {
private auth: any;
constructor(private af : AngularFire, @Inject(FirebaseApp) fa : any) {
this.auth = fa.auth();
}
onSubmit() {
this.auth.sendPasswordResetEmail(this.user.email)
.then( resp => console.log('sent!') )
.catch( error => console.log('failed to send', error) );
}
}
Notice that you will have to declare your instance of FirebaseApp
as any
for now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With