QuizHour Doc
Buy NowInstallation PlansSupport
  • Introduction
  • Changelogs
  • Getting Started
  • 🚀Admin Setup
    • 1. Flutter Installation
    • 2. Code Setup
    • 3. Firebase Setup
      • 3.1 Firestore Database Setup
      • 3.2 Database Security Rules
      • 3.3 Database Index Setup
      • 3.4 Push Notification Setup
      • 3.5 Firebase Storage Setup
    • 4. Code Configs
    • 5. Upload to Firebase Hosting
    • 6. Admin Credentials Steup
    • 7. Conclusion
  • 📱App Setup
    • 1. Introduction
    • 2. Code Setup
    • 3. Firebase Setup for Android
      • 3.1 Android Package Name Setup on Firebase
      • 3.2 Change Package Name Android
      • 3.3 Generate Debug Certificate
      • 3.4 Generate Release Certificate
      • 3.5 Google Sign In Setup for Android
      • 3.6 Facebook Login Setup for Android
      • 3.7 Additional Firebase Setup for Android
    • 4. Firebase Setup for iOS
      • 4.1 iOS Package Name Setup on Firebase
      • 4.2 Change Package Name iOS
      • 4.3 Facebook Login Setup for iOS
      • 4.4 Apple Login Setup
      • 4.5 Additional Firebase Setup for iOS
    • 5. Push Notification Setup
      • 5.1 Android Notification Setup
      • 5.2 iOS Notification Setup
    • 6. Multi-Language Setup
    • 7. Ads Setup
      • 7.1 Admob Setup for Android
      • 7.2 Admob Setup for iOS
    • 8. App Information Setup
    • 9. Change App Name for Android
    • 10. Change App Name for iOS
    • 11. Change App Icon
    • 12. Change Splash Icon
    • 13. Change App Theme Color
    • 14. Run The App
    • 15. Releasing the Android App
    • 16. Releasing the iOS App
  • ⚒️In-App Purchase Setup
    • 17. Points Store Setup
      • 17.1 Android Setup
      • 17.2 iOS Setup
      • 17.3 Code Setup for IAP
  • ⚒️Customization
    • 1. Customize Intro/On-Boarding Screen
    • 2. Disable Specific Features
    • 3. Import Questions (Bulk Upload)
  • ✨Updates
    • Migrate to the v2.0.0(hotfix-1)
    • Migrate to the v2.0.0
Powered by GitBook
On this page

Was this helpful?

  1. Admin Setup
  2. 3. Firebase Setup

3.2 Database Security Rules

  • From the Firestore Database, Click on the Rules tab and copy and paste the following code below:

Firestore Security Rules
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    
    match /users/{userId} {
    	allow read: if true;
      allow write: if isUserSignedIn() && request.auth.uid == userId || isAdmin();
    }
    
    
    match /questions/{document=**} {
    	allow read : if true;
      allow write: if isUserSignedIn() && (isAdmin() || isEditor());
    }
    
    match /quizes/{document=**} {
    	allow read : if true;
      allow write: if isUserSignedIn() && (isAdmin() || isEditor());
    }
  
    
    match /categories/{document=**} {
    	allow read : if true;
      allow write: if isUserSignedIn() && (isAdmin() || isEditor());
    }
    
    
    // new
    match /notifications/{document=**} {
    	allow read : if true;
      allow write: if isUserSignedIn() && isAdmin();
    }
    
    //new
    match /purchases/{document=**} {
    	allow read : if true;
      allow write: if isUserSignedIn();
    }
    
    //new
    match /user_stats/{document=**} {
    	allow read : if true;
      allow write: if isUserSignedIn();
    }
    
    //new
    match /purchase_stats/{document=**} {
    	allow read : if true;
      allow write: if isUserSignedIn();
    }
    
    match /settings/{document=**} {
    	allow read : if true;
      allow write: if isUserSignedIn() && isAdmin();
    }
    
    match /item_count/{document=**} {
    	allow read: if true;
      allow create, update: if isUserSignedIn() || isAdmin();
    }
    
    function isUserSignedIn (){
    	return request.auth != null;
    }
    
    function isAdmin (){
    	return "admin" in get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role;
    }
    
    function isEditor (){
    	return "editor" in get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role;
    }
    
  }
}
  • Click on Publish button to publish the security rules. That's it.

Previous3.1 Firestore Database SetupNext3.3 Database Index Setup

Last updated 1 year ago

Was this helpful?

🚀