Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

246
Vistas
Firebase realtime database only owner can edit the post

This is how my firebase database looks like:

I am using firebase realtime database. At the moment all users can create a post which is good. All users can delete their post if they are the owner (which is what i want), when a user is editing a post that he does not own, it creates a duplicate of that post with the new updated information.

They are not editing the original post they are duplicating it under their uid. What are the rules so they can't duplicate the post?

those are my rules:

   {
  "rules": {
    ".read": true,
    ".write": "auth != null",
      "posts":{
        "$uid":{
          ".write": "auth != null && auth.uid == $uid"
        }
      }
  }
}

this is my code

const [currentUser, setCurrentUser] = useState();
  const [id, setId] = useState("");
  const [show, setShow] = useState(false);

  useEffect(() => {
    const unsubscribe = auth.onAuthStateChanged(async (userAuth) => {
      if (userAuth) {
        const userRef = await createUserProfileDocument(userAuth);
        userRef.on("value", (snapShot) => {
          setCurrentUser({ key: snapShot.key, ...snapShot.val() });
        });
      }
      if (setCurrentUser(userAuth)) {
      } else if (!userAuth && typeof window !== "undefined") {
        return null;
      }

      const uid = userAuth.uid;
      console.log(uid);
      setId(uid);
    });

    return unsubscribe;
  }, []);

  const postKey = props.farm.postKey;
  console.log(id);

  const DeletePost = () => {
    getFirebase()
      .database()
      .ref(`Users/Posts/`)
      .child(`${id}`)
      .child(`${postKey}`)
      .remove();
  };

  

    const updatePost = (e) => {
      e.preventDefault();
      const obj = {
        ...values,
      };
      const postKey = props.farm.postKey;
      getFirebase()
        .database()
        .ref(`Users/Posts/`)
        .child(`${id}`)
        .child(`${postKey}`)
        .update(obj, (err) => {
          if (err) console.log(err);
        });
    };
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda