How to use the sendPasswordResetEmail() function on the server using the firebase-admin SDK?

前端 未结 3 1051
盖世英雄少女心
盖世英雄少女心 2020-12-11 13:08

In the past, I have used firebase.auth in the web client and once a user creates another user, I link certain security logic:

  • Once the user has been created I s
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 13:46

    I'm sure it doesn't matter anymore, but I had a headache doing this so I'd like to share even if it isn't the greatest answer.

    await admin.auth().createUser(
                {email, password, displayName, phoneNumber, photoURL}
            ).then(function(userRecord) {
                admin.auth().createCustomToken(userRecord.uid).then(function(customToken){
                    createdToken=customToken; 
                    firebase.auth().signInWithCustomToken(createdToken).catch(function(error){
                        return console.log(error)
                    })
                    firebase.auth().onAuthStateChanged(function(user) {
                        user.sendEmailVerification().then(function(){
                            return console.log('It worked')
                        },function(error) {
                            return console.log(error)
                        })
                      });
                })
            })
    

提交回复
热议问题