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

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

    Some time ago I faced the exact same problem and this is how I solved it in typescript:

    admin.initializeApp();
    const db = admin.firestore();
    export const createUsr = functions.https.onCall((data) => {
    
            return admin.auth().createUser({
                email: data.email,
                emailVerified: true,
                password: data.password,
                displayName: data.nombre,
                disabled: false,
                photoURL: data.urldeImagen
            }).then(
                (userRecord) => {
                    console.log('Se creó el usuario con el uid: ' + userRecord.uid);
                    const infoUsr = {
                        Activo: false,
                        Contrasenia: data.password,
                        Correo: data.email,
                        Foto: data.nombrefoto,
                        Llave: userRecord.uid,
                        Nombre: data.nombre,
                        PP: false,
                        Privilegios: data.privilegios,
                        UrldeImagen: data.urldeImagen
                    };
                    //update your db 
                    return db.collection....
                ).catch((error) => {
                    console.log(error);
                    return error
                });
            });
    

提交回复
热议问题