So I'm developing a web app using Firestore and Nuxt, and while I got the authentication working I would like to ensure I am following best practices.
Using Firebase Authentication only gives me an identifier (email in this case) and an UID. Then I created a user collection to store additional data such as:
{
"UID": "6TIupYLKlcOE97b5Fe63uinf6Ik1",
"app_metadata": {
"role": "admin",
"status": "approved"
},
"firstName": "Jon",
"lastName": "Doe"
}
Currently I am doing the following after user is authenticated to get the user's role:
// Getting user details
db.collection('users')
.where('UID', '==', user.uid)
.limit(1)
.get()
.then((snapshot) => {
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data().app_metadata.role)
dispatch('setROLE', doc.data().app_metadata.role)
})
})
.catch((err) => {
console.log('Error getting documents', err);
})
Is there a better way to handle storing additional user data and tie it all together with Firebase Authentication?