Konfiguracja Bazy Danych Firestore
Aby aplikacja mogła poprawnie działać, musisz skonfigurować Reguły Bezpieczeństwa w swojej bazie danych. Domyślnie, nowa baza danych blokuje wszelkie próby odczytu i zapisu danych.

Krok 1: Przejdź do Konsoli Firebase

Otwórz nową kartę w przeglądarce i przejdź do Konsoli Firebase, a następnie wybierz swój projekt.

Krok 2: Otwórz Reguły Firestore

W menu po lewej stronie, w sekcji "Build", kliknij na **Firestore Database**. Następnie, na górze strony, wybierz zakładkę **"Rules" (Reguły)**.

Krok 3: Wklej nowe reguły

Usuń całą istniejącą zawartość w edytorze reguł i wklej poniższy kod. Następnie kliknij przycisk **"Publish" (Opublikuj)**.

rules_version = '2';

service cloud.firestore {
  match /databases/{database}/documents {
  
    function isAdmin(userId) {
      return exists(/databases/$(database)/documents/users/$(userId)) &&
             get(/databases/$(database)/documents/users/$(userId)).data.role == 'admin';
    }

    match /users/{userId} {
      // CREATE: A new user can create their own document.
      allow create: if request.auth != null && request.auth.uid == userId;
      
      // READ, UPDATE: A user can manage their own doc. Admins can manage any doc.
      allow read, update: if request.auth != null && (request.auth.uid == userId || isAdmin(request.auth.uid));

      // DELETE: Only an admin can delete a user document.
      allow delete: if request.auth != null && isAdmin(request.auth.uid);
    }
    
    match /templates/{templateId} {
       // READ: Any authenticated user can read templates.
       allow read: if request.auth != null;
       // WRITE: Only admins can write/update templates.
       allow write: if request.auth != null && isAdmin(request.auth.uid);
    }
    
    match /{collection}/{docId} {
       // CREATE: Any authenticated user can create docs if they own them.
       allow create: if request.auth != null && request.resource.data.userId == request.auth.uid;
       
       // READ, UPDATE, DELETE: Users can manage their own docs, Admins can manage all.
       allow read, update, delete: if request.auth != null && (resource.data.userId == request.auth.uid || isAdmin(request.auth.uid));
    }
  }
}

Gotowe!

Po opublikowaniu nowych reguł, wróć do aplikacji i spróbuj się zalogować lub zarejestrować. Wszystko powinno już działać poprawnie.