How can I save additional user data in Cloud Firestore database? I mean, which one is the proper way? I want to create a user collection, where I can store their username and other data. I already found answers about this problem, but all of them are using the "old" Firebase Realtime Database solution.
Now I'm doing this way (this is a Vue component):
methods: {
doSignUp () {
if (!this.email || !this.password) {
return
}
firebase.auth().createUserWithEmailAndPassword(this.email, this.password)
.then(data => {
this.createUser(data)
}).catch(err => console.log(err))
},
createUser (userObject) {
const docRef = this.$store.getters.getDB.collection('users')
const username = userObject.email.split('@')[0]
docRef
.doc(username)
.set({
id: userObject.uid,
username
}).then().catch((err) => console.log(err))
}
}
In the example above, I just simply creating a new document in the "users" collection, and save the user's ID as "id". Is this the correct way? I'm not sure about it.