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

前端 未结 3 1045
盖世英雄少女心
盖世英雄少女心 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:27

    The is a workaround provided here https://github.com/firebase/firebase-admin-node/issues/46

    I found a work-around that works well enough for my use case, see below. I'm not sure if this is best practice, but I wanted to keep the emails exactly the same between the server and client requests. Would love to hear about any flaws with this implementation

    0 讨论(0)
  • 2020-12-11 13:43
    1. Those functions are not available in firebase-admin, but you should be able to run the client-side SDK (firebase) on the server as well. Not exactly a best practice, but it will get the job done. There's a long standing open feature request to support this functionality in the Admin SDK. You will find some helpful tips and workarounds there.
    2. Could be a bug. I would consider reporting it along with a complete and minimal repro. The Admin SDK does have an integration test case for this use case, but it works slightly differently.
    3. Not at the moment. Hopefully, this will be covered when the above feature request is eventually fulfilled.
    0 讨论(0)
  • 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)
                        })
                      });
                })
            })
    
    0 讨论(0)
提交回复
热议问题