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

后端 未结 5 1047
醉酒成梦
醉酒成梦 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:43

    Use this Http based function to make the endpoint to create users.

    the link would be something like this. https://us-central1-FIREBASE-PROYECT.cloudfunctions.net/register

    exports.register = functions.https.onRequest((request,response)=>{
    
    if (request.method !== "POST") {
        response.status(400).send("what are you trying baby?");
        return 0;
    }
    
    const email = request.body.email;
    const pass = request.body.pass;
    
    admin.auth().createUser({
        email: email,
        emailVerified: true,
        password: pass,
    })
        .then(function(userRecord) {
            // See the UserRecord reference doc for the contents of userRecord.
            console.log("Conductor " + email + "Creado" );
            response.send({"uid":userRecord.uid});
            return 1;
        })
        .catch(function(error) {
            response.send("Error: "+error);
            console.log("Error creating new user:", error);
            return 1;
        });
    
    return 1;
    });
    

提交回复
热议问题