简体   繁体   English

Firebase firestore 未使用最近创建的 uid 创建文档

[英]Firebase firestore not creating doc with recently created uid

I have a firebase firestore db and I want to create a user then add a record to the db with the doc name as the uid.我有一个 firebase firestore 数据库,我想创建一个用户,然后将一条记录添加到数据库中,并将文档名称作为 uid。

This doesn't throw any errors in the console, but also does not create the record?这不会在控制台中引发任何错误,但也不会创建记录?

firebase.auth().createUserWithEmailAndPassword(
        customerEmail.current.value, 
        customerPassword
    ).then(() => {
        console.log("UID!!!!!!!!!!!!!!!!!!!!!!!", firebase.auth().currentUser.uid)
        firebase
        .firestore()
        .collection('sessions')
        .doc(firebase.auth().currentUser.uid).set(
            {...context.state}
        )
    })

I have no idea why this works and the code above doesn't - and it still doesn't do anything when it saves successfully!我不知道为什么这行得通,而上面的代码却没有——当它成功保存时它仍然没有做任何事情!

firebase.auth().createUserWithEmailAndPassword(
        customerEmail.current.value, 
        customerPassword
    ).then(function(user) {
        console.log("UID!!!!!!!!!!!!!!!!!!!!!!!", user, user.user.uid)
        firebase
        .firestore()
        .collection('sessions')
        .doc(user.user.uid).set(
            {...context.state}, 
            function(error) {
                if (error) {
                  console.log("Data could not be saved." + error);
                } else {
                  console.log("Data saved successfully.");
                }
              }
        )
    })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM