Picki
Picki

Reputation: 499

Duplicate data between Firebase Authentication and Firestore

I have a small question about managing data between Firebase Authentication and Firestore.

For example: The Firebase Authentication API stores the email of the user. But we also use Firestore to store the other details about the user. So the question is...

Should we also store the email on Firestore ?

I feel that a duplicate data is never a good idea. But having the email directly in Firestore should be faster and easy to access.

Thank you

Upvotes: 2

Views: 397

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599776

I feel that a duplicate data is never a good idea.

When working with NoSQL solutions I'd highly recommend letting that feeling go. Read NoSQL data modeling and watch Getting to know Cloud Firestore for more on this.

One of the things you'll learn from that is that your data model will typically evolve for the use-cases your app needs. For example, if you want to allow the user to see or search all email addresses, that functionality is not standard available in the client-side Firebase Authentication SDK. This means you have a few options to build this functionality for your users:

  1. The server-side Admin SDKs of Firebase Authentication do have the option to look up the email address for a user, or to list users. So you could wrap this functionality in an end-point you create and secure (for example with Cloud Functions).
  2. You can also write the user information to Cloud Firestore (or the Realtime Database) when the users registers, and then look it up there from within the app, using Firebase's security rules to ensure all access to the data is authorized.

This is just one example, and as I hope is clear, it is based on speculating that your app needs certain functionality. But it's quite common that developers store user information that is also in Firebase Authentication in a database too.

Upvotes: 1

Related Questions