Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
Firestore deniega el permiso para crear/empujar colección

Soy nuevo en firebase / firestore y estoy tratando de crear una nueva colección al iniciar sesión y autenticar a un usuario, en el lado del cliente y usando React. Leí algunos otros artículos aquí y configuré las reglas de la base de datos en verdadero tanto para lectura como para escritura, pero aún así, sigo recibiendo un error en la base de datos de Firestore, aunque funciona perfectamente si inicializo una base de datos en tiempo real. Además, puedo obtener y leer datos, pero no escribirlos.

El código que tengo es bastante simple:

 export default function Login() { const [isAuthenticated, setAuthenticate] = useState(false); const [newEditor, setNewEditor] = useState(""); const uiConfig = { signInFlow: "popup", signInOptions: [firebase.auth.GoogleAuthProvider.PROVIDER_ID], callbacks: { signInSuccessWithAuthResult: (user) => { console.log("success"); createUserRoles(newEditor); }, }, }; useEffect(() => { firebase.auth().onAuthStateChanged((user) => { if (user) { if (user.email.split("@")[1] === "something.com") { setAuthenticate(!!user); setNewEditor(user.email); console.log(newEditor); } else { console.log("not allowed"); } } }); }); const createUserRoles = (user) => { //on login the user will be added to editors collection with default value of reviewer console.log("hello from createeee"); const editorsRef = firebase.database().ref("editors"); const editor = { email: "user.email", role: "reviewer", lastSession: Date.now(), }; editorsRef.push(editor); }; return ( .....

y mis reglas se establecen como tales:

 service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read: if true; allow write: if true; } } }

¿Alguien tiene una idea de cómo puedo hacer esto?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En primer lugar, verifique que esté incluyendo el SDK de Firestore en su código. Entonces... está usando la sintaxis RTDB para intentar agregar un documento a Firestore en createUserRoles . Debe cambiarlo a la sintaxis de Firestore:

 const createUserRoles = async (user) => { //on login the user will be added to editors collection with default value of reviewer console.log("hello from createeee"); // This is RTDB syntax for a ref // const editorsRef = firebase.database().ref("editors"); // Try this instead const editorsRef = firebase.firestore().collection("editors"); const editor = { email: "user.email", role: "reviewer", lastSession: Date.now(), }; // This is how you add an item to RTDB // editorsRef.push(editor); // This is the Firestore way to create a new record with a random, unique document id await editorsRef.add(editor); };

No también que las lecturas y escrituras con Firestore (al igual que RTDB) sean asincrónicas, por lo que debe usar async/await (como agregué) o then/catch promesas.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!