I have created a prototype of my App In Firebase Studio and set up a new database in Firestore. I also added the Firebase App In Firebase Control Project and configured Firebase in the prototype app. When a user signs up, I can see their information in the Firebase authorization table, but no user records are created in the collection. The same issue occurs with other functionalities involving collections—I’m unable to create any entries, even with very basic rules set up. All configurations, including Firebase rules and authentication, are in place. I am attaching the logs. Could someone help me figure out how to automatically store signup user information in the user collection?
rules_version = ‘2’;
service cloud.firestore {
match /databases/{database}/documents {
// Existing rules for ‘users’ collection
match /users/{userId} {
// Allow user to create their own document when they first sign up.
allow create: if request.auth.uid == userId;
// Allow a user to read their OWN document. This covers both existing and non-existing documents
// so that onSnapshot can correctly determine docSnapshot.exists().
allow read: if request.auth != null && request.auth.uid == userId;
// Additionally, allow read for admin users to any document.
// This rule is separate to avoid issues with get() on non-existent documents for new users.
allow read: if request.auth != null &&
exists(/databases/$(database)/documents/users/$(request.auth.uid)) &&
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'admin';
// Allow user to update their own document IF it exists.
// Or if the requesting user is an admin.
allow update: if request.auth != null && (
(request.auth.uid == userId && exists(resource)) || // User updates own existing doc
(exists(/databases/$(database)/documents/users/$(request.auth.uid)) && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'admin') // Admin updates any doc
);
// Only admins can delete user documents.
allow delete: if request.auth != null &&
exists(/databases/$(database)/documents/users/$(request.auth.uid)) &&
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'admin';
}
// New rules for 'feedbacks' collection
match /feedbacks/{feedbackId} {
allow read: if request.auth != null && request.auth.uid == resource.data.userId;
allow create: if request.auth != null && request.auth.uid == request.resource.data.userId;
allow update: if request.auth != null && request.auth.uid == resource.data.userId;
allow delete: if request.auth != null && request.auth.uid == resource.data.userId;
// Admin access to all feedbacks
allow read, write, delete: if request.auth != null &&
exists(/databases/$(database)/documents/users/$(request.auth.uid)) &&
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'admin';
}
}
}
