使用angular/spring引导通过firebase生成验证邮件
我正在开发一个带有firebase(仅限身份验证)、angular和spring boot的应用程序。我想在创建用户后发送电子邮件验证。我有两个选项可以通过提供电子邮件和密码来创建用户使用angular/spring引导通过firebase生成验证邮件,angular,firebase,spring-boot,firebase-authentication,Angular,Firebase,Spring Boot,Firebase Authentication,我正在开发一个带有firebase(仅限身份验证)、angular和spring boot的应用程序。我想在创建用户后发送电子邮件验证。我有两个选项可以通过提供电子邮件和密码来创建用户 通过注册页面注册(任何人) 管理员可以在登录到系统后创建用户 在角度7中 SignUp(email, password) { return this.afAuth.auth.createUserWithEmailAndPassword(email, password) .then((result)
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
})
}
如果创建了新帐户,用户将自动登录。-
上面的代码将用户数据作为当前用户返回因此第二个场景失败(即使管理员登录,一旦他创建了一个用户,也会自动将管理员状态更改为新用户状态)。因此我通过后端创建了一个新用户
在弹簧靴中
CreateRequest request = new CreateRequest().setEmail(user.getEmail()).setPassword(user.getPassword());
UserRecord userRecord = FirebaseAuth.getInstance().createUser(request);
这是在不更改登录用户状态的情况下成功创建用户
有没有办法向第二个场景发送电子邮件验证(通过后端或前端)?提前感谢。好吧,我更新了后端(Spring boot)中的最新依赖项,它具有
generateEmailVerificationLink()代码>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.8.1</version>
</dependency>
// 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);