首页 文章

使用node.js使用firebase auth创建新用户时设置firestore文档

提问于
浏览
1

我正在使用firebase Cloud 功能,firebase auth和firestore . 我之前使用firebase数据库完成了这个,但是不确定firestore如何将users集合中的文档设置为新创建的firebase auth用户的uid .

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

const db = admin.firestore()

exports.createUser  = functions.auth.user().onCreate(event => {

 const uid  = event.data.uid;
 console.log(uid);

 db.collection('users').doc(uid);


});

以上内容在日志中完成,但是未在数据库中设置uid . 我需要在某个阶段打电话吗?

谢谢 .

1 回答

  • 2
    const colloection = db.collection("users")
            const userID = "12345" // ID after created the user.
            colloection.doc(userID).set({
                name : "userFoo", // some another information for user you could save it here.
                uid : userID     // you could save the ID as field in document.
            }).then(()=>{
                console.log("done")
            })
    

相关问题