firebase admin SDK 创建用户并发送验证邮件 [英] firebase admin SDK create user and send verification email

查看:25
本文介绍了firebase admin SDK 创建用户并发送验证邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用 firebase admin SDK 创建用户后发送验证电子邮件?我正在尝试结合 createUser 函数sendEmailVerification 函数有人可以指出提示或答案吗?谢谢

How can I send a verification email after I create a user with firebase admin SDK? I am trying to combine createUser function and sendEmailVerification function could somebody indicate a hint or an answer? thanks

用户创建由已登录应用的管理员用户完成,因此管理员用户只是在仪表板上创建用户.这与注册方式完全不同.

the user creation is being done by an admin user who is already signed in in the app, so the admin user is just creating users on the dashboad. This is completely different from the registeration methods.

我尝试遵循 bojeil 的回答,但我仍然坚持用户使用自定义令牌登录的步骤.它与我当前的管理员用户会话发生冲突,管理员用户被踢出,而是新用户登录,即使我注销新用户,管理员用户仍然不在,需要登录才能重新登录应用程序.

I tried to follow bojeil's answer, I am still stuck with the step that user signs in with the custom token. It gets into conflict with my current admin user session, the admin users gets kicked out and instead the new user is signed in and even when I sign out the new user, the admin user is still out and needs to sign in to get back into the app.

这是我获得自定义令牌后在应用程序中的代码:

here is my code inside the app after I get the custom token:

$http.post('/.custom-token', {uid: $scope.data.data.uid})
        .then(function (response) {
            console.log("custom token here:", response.data.token);
            firebase.auth().signInWithCustomToken(response.data.token)
                .then(function (firebaseUser) {
                    firebaseUser.sendEmailVerification();
                    firebase.auth().signOut().then(function() {
                        // Sign-out successful.
                        console.log("signed out success");
                    }, function(error) {
                        // An error happened.
                    });
                })

                .catch(function(error) {
                    // Handle Errors here.
                    var errorCode = error.code;
                    var errorMessage = error.message;
                    // ...
                });

        });

因此,我获取令牌,登录新用户,发送电子邮件验证链接,然后注销新用户.但是我正在执行所有这些操作的管理员用户也被注销了.我在这里错过了什么?

so, I get the token, sign in the new user, send the email verification link, and then, sign out the new user. But my admin user who is doing all of this gets signed out as well. what am I missing here?

推荐答案

好的,您可以这样做,但您可能会遇到配额限制:

OK this is what you can do but you may hit quota limitations:

  • 包括 firebase-admin 模块.
  • 包括 firebase 客户端模块.
  • 使用 admin sdk,通过 createUser 创建新用户
  • 当该承诺解决时,获取创建的用户的 uid.
  • 使用 admin sdk,为该 uid 创建自定义令牌.
  • 使用客户端 sdk,使用该自定义令牌 signInWithCustom 令牌.
  • 过程中返回一个用户,调用 user.sendEmailVerification()
  • 从客户端 SDK 注销该用户.

这篇关于firebase admin SDK 创建用户并发送验证邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆