Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't tempt users with actions they can't do #39

Open
oliverjam opened this issue Oct 15, 2021 · 0 comments
Open

Don't tempt users with actions they can't do #39

oliverjam opened this issue Oct 15, 2021 · 0 comments

Comments

@oliverjam
Copy link

So this is more of a UX concern—you're showing delete buttons for every post, even ones I don't own. Clicking one doesn't do anything at all (which is good! much better than letting me delete other people's posts 😅). However it would be nice to both only show the button for posts I can delete (i.e. putting a condition to check the owner when you render the posts list), and to show some kind of error if I do manage to send a POST to delete a post I don't own.

function deletePost(postId, user_id) {
const DELETE_POST = `DELETE FROM posts WHERE id=$1 AND user_id=$2`;
return db.query(DELETE_POST, [parseInt(postId, 10), user_id]);
}

This is a clever solution—using SQL to avoid writing your own checks in JS. However in this case it means you don't have a way to determine whether the delete happened or not. If you want to show the user an error when they try to delete a post that they don't own you'll have to do that check in JS before making the DB query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant