Reputation: 35
hello Im trying to write to firestore after a user signs up, It's not showing up on the firestore colelctions where am i going wrong?
the error that comes up is
`"FirebaseError: Function CollectionReference.doc() requires its first argument to be of type non-empty string, but it was: undefined". I've been stuck on this for a few days as I am new to firebase.
thank you! :)
export default class Register extends React.Component {
static navigationOptions = {
headerShown: false
};
state = {
name:"",
email: "",
password: "",
errorMessage: null
};
handleSignUp = () => {
try {
firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
.then(function(user){
const user2 = firebase.auth().currentUser;
const currentUser = user.uid
const db = firebase.firestore();
db.collection('users')
.doc(user.id)
.set({
email: user2.email,
name: this.state.name
})
});
} catch (err) {
Alert.alert('There is something wrong!', err.message);
}
}
Upvotes: 0
Views: 26
Reputation: 3499
The error message is telling you quite explicitly that user.id is undefined. You may notice in YOUR OWN CODE that you earlier used user.uid
So what you're likely looking for is:
handleSignUp = () => {
try {
firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
.then(function(user){
const user2 = firebase.auth().currentUser;
const currentUser = user.uid
const db = firebase.firestore();
db.collection('users')
.doc(currentUser)
.set({
email: user2.email,
name: this.state.name
})
});
} catch (err) {
Alert.alert('There is something wrong!', err.message);
}
}
Upvotes: 1