From Link.. It goes something like this where the user Name gets save to firestore and auth_userRecord.
const newUser = {
displayName: data.name,
//...
};
const client = await admin.auth().createUser(newUser);
await admin.auth().setCustomUserClaims(client.uid, {
client: true
});
const clientDetails = {
name: data.name,
//...
};
await admin.firestore().collection('users').doc(client.uid).set(clientDetails);
Now I'm wondering when a user change his/her name. I will have to update the user Name in both firestore and auth_userRecord.
So my question is why will one want to save a user Name in both firestore and auth_userRecord?
CodePudding user response:
This also depends on your use case. For example, if you are building an application where data is specific to user such as storing notes or simple to do lists, then it's completely optional to store such information in Firestore.
However, if you are building a blog side or something like Stackoverflow where you also need to show author's details then it might be easier to fetch that information directly from Firestore rather than fetching that user's data from Firebase Authentication.
Do note that, if you were to fetch user's data like display name from Firebase Auth, you would have to use Cloud functions because client SDKs can get data of current user only. But when data is stored in Firestore (or realtime DB), you can fetch user info from client directly.