I am using firebase authentication on my reactJS application. When a user signs up, an entry is added into firestore to store some account details at user/(UID).
I need to create firestore rules that willL
- Prevent unauthenticated users from reading and writing to firestore
- Only allow users to read their own data in firestore Users/(users UID)
- Allow newly registered users to write to firestore so data can be added for their account.
I have tried the following:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
match /users/{userId}/{document=**} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
allow read;
allow write: if request.auth != null;
}
}
}
But i am receiving an email each day from Firebase saying my rules are insecure and anyone can write to my database. How can i fix this?