【问题标题】:Generate Verification Mail through firebase using angular/spring-boot使用 angular/spring-boot 通过 firebase 生成验证邮件
【发布时间】:2019-10-03 19:37:54
【问题描述】:

我正在开发一个带有 firebase(仅身份验证)、角度和弹簧启动的应用程序。创建用户后,我想发送电子邮件验证。我有两个选项可以通过提供电子邮件和密码来创建用户。

  1. 通过注册页面注册(任何人)
  2. 管理员可以在登录系统后创建用户。

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

上面的代码以当前用户的身份返回用户数据。 所以第二种情况失败(即使是管理员登录,一旦他创建了一个用户,它会自动将管理员状态更改为新的用户状态)。所以我通过后端创建了一个新用户。

Spring Boot

CreateRequest request = new CreateRequest().setEmail(user.getEmail()).setPassword(user.getPassword());
UserRecord userRecord = FirebaseAuth.getInstance().createUser(request);

这是在不更改登录用户状态的情况下成功创建用户。

有没有办法向第二种情况发送电子邮件验证(通过后端或前端)?提前致谢。

【问题讨论】:

    标签: angular firebase spring-boot firebase-authentication


    【解决方案1】:

    好吧,我更新了后端(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);
    

    【讨论】:

      猜你喜欢
      • 2016-03-01
      • 2019-07-02
      • 2015-06-03
      • 2021-11-15
      • 2013-05-31
      • 2023-03-27
      • 2017-11-08
      • 1970-01-01
      • 2019-01-14
      相关资源
      最近更新 更多