I am trying to register User with email and password. If register function works then a mail will be send to user's email address, this mail must contain a link that the user will click to confirm email address. I have try to do this with the AngularFireAuth.auth.currentUser.sendEmailVerification() function it doesn't work: This version of AngularFire/Firebase does'nt support this method. Can you help me ?
import {Injectable, NgZone} from '@angular/core';
import {AngularFireAuth} from '@angular/fire/auth';
import {first} from 'rxjs/internal/operators/first';
import * as firebase from 'firebase';
import {AngularFirestore} from '@angular/fire/firestore';
@Injectable({
providedIn: 'root'
})
export class AuthService {
public userId: string;
constructor(
private afAuth: AngularFireAuth,
private afStore: AngularFirestore,
public ngZone: NgZone
) { }
getUser(): Promise<firebase.User>{
return this.afAuth.authState.pipe(first()).toPromise();
}
loginWithEmailAndPassword(email: string, password: string): Promise<firebase.auth.UserCredential>{
return this.afAuth.signInWithEmailAndPassword(email, password);
}
async registerWithEmailAndPassword(email: string, password: string): Promise<firebase.auth.UserCredential>{
const newUserCredential: firebase.auth.UserCredential = await this.afAuth.createUserWithEmailAndPassword(email, password);
this.afStore.collection('users').doc(`${newUserCredential.user.uid}`).set({
uid: newUserCredential.user.uid,
email: newUserCredential.user.email,
created_at: firebase.firestore.FieldValue.serverTimestamp()
}).then(function() {
console.log("user is registered");
this.sendEmailVerification();
}).catch(function(error) {
console.error("Error adding document: ", error);
});
return newUserCredential;
}
async sendEmailVerification() {
}
resetPassword(email: string): Promise<void>{
return this.afAuth.sendPasswordResetEmail(email);
}
logout(): Promise<void>{
return this.afAuth.signOut();
}
async createPersonalProfile(){
}
}