用angular firebase发送邮件给不同的邮箱来验证注册



我能够在注册前验证用户的电子邮件。但是我想要收到验证邮件到我的邮箱来完成注册过程。我想收到通知到我的电子邮件地址,我的批准后,只有注册过程完成。我查过邮箱验证: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');
});
} 

注册:

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')
})
})
}
}

听起来你想要批准用户可以使用你的应用程序,这与允许他们验证自己的电子邮件地址不同。

虽然这是一个有效的用例,但Firebase Authentication并没有为这个用例内置功能。

Firebase Authentication只处理身份验证部分,因此允许用户提供他们的凭据——并验证这些凭据。只允许使用经过验证的电子邮件地址的用户或您已批准的用户使用应用程序是授权,并且是您必须自己构建的应用程序逻辑的一部分。

对于只允许批准的用户访问应用程序/数据,常见的流程是:

  1. 在数据库中创建一个批准的用户列表,或者在你已经拥有的配置文件中添加一个用户不能自己设置的isApproved字段。
  2. 在验证用户后的应用程序代码中,检查他们是否在允许的用户列表中,如果他们是,则只允许他们在应用程序中继续进入下一个屏幕。
  3. 如果您的数据库安全规则只允许在批准用户列表中的用户读取数据。
  4. 在任何自定义后端代码中,在执行请求之前检查用户是否被批准。

最新更新