0

I'm building a social media app using Firebase and I want each user to have a unique username that can be later changed to something else like Instagram etc.

How can I set up a security rule for Cloud Firestore to prevent a WRITE operation when the incoming "username" data already exist in another document

User Collection Data Structure

  • documentID = user.uid (from Firebase Auth)
  • username
  • email
  • first_name
  • last_name
Rezia
  • 15
  • 1
  • 4
  • There is no way to ensure unique **values** in Firestore security rules. You'll need an (additional) collection where you use the username as the ID of the documents. This has been covered multiple times before, so I recommend checking out some of these results: https://stackoverflow.com/search?q=%5Bgoogle-cloud-firestore%5D+unique+username – Frank van Puffelen Dec 13 '21 at 21:09

0 Answers0