Firebase管理员SDK创建用户并发送验证电子邮件 [英] firebase admin SDK create user and send verification email

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

问题描述

在使用Firebase管理员SDK创建用户后,如何发送验证邮件?
我正在尝试将 createUser功能 sendEmailVerification函数
可以有人指示提示或答案?谢谢

update:



用户创建是由已经登录应用程序,所以管理员用户只是在dashboad上创建用户。这与注册方法完全不同。



update 2:



我试着按照bojeil's答案,我仍然坚持用户使用自定义令牌登录的步骤。它与我目前的管理员用户会话发生冲突,管理员用户被踢出,而新用户登录,即使当我注销新用户时,admin用户仍然出局,需要登录才能重新登录

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

  $ 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(){
//注销成功
console.log(注销成功 );
},函数(错误){
//发生错误
});
$)
$ b $ .catch(function(error){
//处理错误
var errorCode = error.code;
var errorMessage = error.message;
// ...
});

});

所以,我得到令牌,登录新用户,发送邮件验证链接,然后,注销新用户。
但是我的管理员用户正在做所有这些也被注销。
我在这里丢失了什么?

解决方案

确定这是你可以做的,但你可能会遇到配额限制: / b>


  • 包含firebase-admin模块。

  • 包含firebase客户端模块。 b $ b
  • 使用admin sdk,通过createUser

  • 创建新用户,当该承诺解析时,获取创建的用户的uid。

  • 使用admin sdk为该uid创建自定义标记。
  • 使用客户端sdk,signInWithCustom标记使用该自定义标记。
  • 返回用户该过程调用user.sendEmailVerification()
  • signOut从客户端SDK中输出该用户。


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

update:

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.

update 2:

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:

  • Include the firebase-admin module.
  • Include the firebase client module.
  • using admin sdk, create the new user via createUser
  • when that promise resolves, get the uid of the user created.
  • using admin sdk, create custom token for that uid.
  • using client sdk, signInWithCustom token using that custom token.
  • A user is returned in the process, call user.sendEmailVerification()
  • signOut that user from the client SDK.

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

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