Davtho1983
Davtho1983

Reputation: 3954

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.

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}
        )
    })

Upvotes: 0

Views: 289

Answers (1)

Davtho1983
Davtho1983

Reputation: 3954

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.");
                }
              }
        )
    })

Upvotes: 1

Related Questions