我正在开发一个带有Firebase(仅仅身份验证),角度启动和弹簧启动的应用。创建用户后,我想发送电子邮件验证。我有两个通过提供电子邮件和密码来创建用户的选项。
在 Angular 7
中SignUp(email, password) {
return this.afAuth.auth.createUserWithEmailAndPassword(email, password)
.then((result) => {
// You have been successfully registered!"
this.afAuth.auth.currentUser.sendEmailVerification()
.then(() => {
// Please verify your email
})
}).catch((error) => {
// Error while registering a user
})
}
如果创建了新帐户,则用户将自动登录。 -Firebase Ref
上面的代码以当前用户的身份返回用户数据。 因此第二种情况失败(即使管理员登录,一旦他创建了用户,它也会自动将管理员状态更改为new用户状态)。因此,我通过后端创建了一个新用户。
在 Spring Boot
中CreateRequest request = new CreateRequest().setEmail(user.getEmail()).setPassword(user.getPassword());
UserRecord userRecord = FirebaseAuth.getInstance().createUser(request);
这成功创建了一个用户,而没有更改登录用户的状态。
是否有任何方法(通过后端或前端)将电子邮件验证发送到第二种情况?预先感谢。
答案 0 :(得分:0)
好吧,我更新了后端{Spring-boot}中具有generateEmailVerificationLink();
的最新依赖项
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.8.1</version>
</dependency>
因此可以生成验证邮件并通过自定义邮件服务发送。 Generate verification link
// Generating verification link with the help of firebase
String link=FirebaseAuth.getInstance().generateEmailVerificationLink(user.getEmail());
// Sending the link through custome mail service
emailService.sendMail("Your mail id", user.getEmail(), "Verfication email", link);