Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it necessary to save a user NAME in auth user Record and also in firestore?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading