test
hi
Fix "Missing or insufficient permissions" (Firestore)
The app needs Firestore Rules (and an Index for featured blogs).
Checklist: Use Firestore Database → Rules (not Realtime Database). Project must match .env → NEXT_PUBLIC_FIREBASE_PROJECT_ID. After editing, click Publish, then hard-refresh the app (Ctrl+Shift+R).
Option A: Temporary open rules (test only)
If you still see the error, try this first. In Firebase Console → Firestore → Rules, replace everything with the block below and click Publish. This allows all read/write to the blog data (for testing only).
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /blogs/{blogId} {
allow read, write: if true;
match /comments/{commentId} {
allow read, write: if true;
}
match /likes/{userId} {
allow read, write: if true;
}
}
}
}
If the error goes away, the problem was rules. Then switch to Option B for proper security.
Option B: Recommended rules
1. Turn on Firestore and set Rules
- Open Firebase Console → your project.
- Go to Build → Firestore Database.
- If the database is not created yet, click Create database, choose Start in test mode (we’ll replace with proper rules next), pick a region, then Enable.
- Open the Rules tab.
- Replace the entire rules editor content with the rules below.
- Click Publish.
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /blogs/{blogId} {
allow read: if true;
allow create, update, delete: if request.auth != null;
match /comments/{commentId} {
allow read: if true;
allow create: if request.auth != null;
allow update, delete: if request.auth != null && request.auth.uid == resource.data.userId;
}
match /likes/{userId} {
allow read: if true;
allow create, delete: if request.auth != null && request.auth.uid == userId;
}
}
}
}
After publishing, the "Missing or insufficient permissions" error for normal app usage should be resolved.
2. Create the index for "Featured" blogs
The "From the blog" section uses a query: featured == true ordered by createdAt desc. Firebase requires a composite index for this.
Easiest: When you see the error "The query requires an index. You can create it here: https://...", click that link. It opens the Firebase Console with the index pre-filled; click Create and wait a few minutes for the index to build.
Or create manually:
- Firebase Console → Firestore → Indexes → Create index.
- Collection ID:
blogs - Fields:
featured(Ascending),createdAt(Descending) - Query scope: Collection → Create.
Summary
- Rules: Anyone can read blogs/comments/likes; only signed-in users can create/update/delete blogs and create comments/likes; comment edit/delete and like doc id are restricted as in the rules above.
- Index: One composite index on
blogswithfeatured(Ascending) andcreatedAt(Descending).
After both are in place, reload the app and try again.