Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

258
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda