Can I create a user on Firebase Authentication in Cloud Functions Http Trigger?

后端 未结 5 1052
醉酒成梦
醉酒成梦 2021-01-02 13:18

Is it possible to create users (email/password type) from inside the Cloud Functions? I am searching for reference to this, but found nothing.

5条回答
  •  一生所求
    2021-01-02 13:42

    Base on answer of @mike-brian-olivera I make a fucntion cloud you can call on front end

    exports.register = functions.https.onCall((data, context) => {
        const { email, pass } = data;
    
        return admin
            .auth()
            .createUser({
                email,
                password: pass,
            })
            .then(userRecord => {
                // See the UserRecord reference doc for the contents of userRecord.
    
                console.log({ uid: userRecord.uid });
                return { success: userRecord.uid };
            })
            .catch(error => {
                return { error: error.message };
            });
    });
    

提交回复
热议问题