Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularFire 2 sendPasswordResetEmail

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.

like image 837
jona jürgen Avatar asked Jul 07 '16 07:07

jona jürgen


People also ask

What is AngularFireAuth?

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.


1 Answers

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.

like image 156
Marcos Silva Avatar answered Sep 30 '22 17:09

Marcos Silva