Button and Action Visibility
You'll learn how to show or hide action buttons (delete, edit, publish) based on whether a user has permission to perform those actions.
What This Means
Even when a user can see a resource, they shouldn't always see every action available for it. A viewer shouldn't see a "Delete" button, a basic user shouldn't see "Promote to Admin," and an author shouldn't see "Edit" on someone else's post. Button visibility creates a cleaner, more intuitive interface while preventing confused users from attempting actions they can't complete.
The Core Idea
You conditionally render action buttons by checking the user's role or permissions before displaying UI elements. This is presentational security—it improves UX but doesn't replace server-side authorization checks.
Think of it like a restaurant menu: regular customers see standard options, but VIP members see exclusive items. The kitchen (server) still validates orders, but the menu (UI) prevents confusion upfront.
Practical Pattern
Based on the roles you're storing in your frontend state (from lesson 1629), you check permissions before rendering:
const canDelete = user.role === 'admin' || user.role === 'moderator';
const canEdit = user.id === post.authorId || user.role === 'admin';
return (
<div>
{canEdit && <button>Edit Post</button>}
{canDelete && <button>Delete Post</button>}
<button>View Post</button> {/* Everyone sees this */}
</div>
);
This creates a personalized interface where users only see actions they're authorized to attempt.
Key Takeaway: Control button visibility with conditional rendering based on user roles or permissions to create intuitive, role-appropriate interfaces—but always enforce authorization on the server side as the true security boundary.