In this episode, we tackle a common issue with nested replies—preventing users from replying endlessly to replies, which can get really messy! Right now, the app allows users to keep replying to replies, resulting in unlimited levels of nesting (even if the UI doesn't always show it).
We'll start by looking at the frontend. The first quick fix is to just remove the "Reply" button from nested replies, so users don't even see the option. You'll see how to introduce an easy rule to hide the reply link if a comment already has a parent. This way, only top-level comments are reply-able.
But, as always, we don't stop at the frontend—anyone clever could still forge a request and sneak in a reply to a reply. So, we also tighten up our backend by adding an authorization policy that determines whether a comment is eligible for a reply. If the comment already has a parent (i.e., it's a reply itself), the policy denies further nesting.
By the end, we check that the frontend no longer shows the reply button for anything but top-level comments, and the backend will refuse any request trying to break this rule. Now, we've got a clean, manageable one-level reply structure. No more infinite reply chains!