I have implemented email verification for users before registration. However, I would like to receive a verification email to my own email address in order to finalize the registration process. I want to be notified via email and only after my approval should the registration process be completed. The file where I have checked the email verification is: auth-service.ts
async SignIn(email,password)
{
const loading =await this.LoadingCtrl.create({
message:'Authenticating..',
spinner:"crescent",
showBackdrop:true
});
loading.present();
this.afauth.setPersistence(firebase.default.auth.Auth.Persistence.LOCAL)
.then(()=>{
this.afauth.signInWithEmailAndPassword(email,password)
.then((data)=>{
if(!data.user.emailVerified){
loading.dismiss();
this.toast('Please check your credentials','warning');
this.afauth.signOut();
}else{
loading.dismiss();
this.router.navigate(['/home']);
}
})
.catch(error=>{
loading.dismiss();
this.toast(error.message,'danger');
})
})
.catch(error=>{
loading.dismiss();
this.toast(error.message,'danger');
});
}
In order to register:
async register(){
if(this.firstname && this.lastname && this.email && this.password){
const loading =await this.loadingCtrl.create({
message:'Processing...',
spinner:'crescent',
showBackdrop:true
});
loading.present();
this.afauth.createUserWithEmailAndPassword(this.email,this.password)
.then((data)=>{
data.user.sendEmailVerification();
this.afs.collection('user').doc(data.user.uid).set({
'userId':data.user.uid,
'userEmail':this.email,
'userFirstname':this.firstname,
'userLastname':this.lastname
})
.then(()=>{
loading.dismiss();
this.toast('Registration Success','success');
this.router.navigate(['/login']);
})
.catch(error=>{
loading.dismiss();
this.toast(error.message,'danger')
})
})
}
}