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

245
Views
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
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!