Skip to content

Commit

Permalink
Dont allow banned users to vote in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-sherman committed Dec 16, 2024
1 parent a040f87 commit e8af35b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/frontpage/app/(app)/_components/post-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { revalidatePath } from "next/cache";
import { ReportDialogDropdownButton } from "./report-dialog";
import { DeleteButton } from "./delete-button";
import { ShareDropdownButton } from "./share-button";
import { isBanned } from "@/lib/data/db/user";

type PostProps = {
id: number;
Expand Down Expand Up @@ -54,7 +55,10 @@ export async function PostCard({
<VoteButton
voteAction={async () => {
"use server";
await ensureUser();
const user = await ensureUser();
if (await isBanned(user.did)) {
throw new Error("Author is banned");
}
await createVote({
subjectAuthorDid: author,
subjectCid: cid,
Expand All @@ -64,7 +68,10 @@ export async function PostCard({
}}
unvoteAction={async () => {
"use server";
await ensureUser();
const user = await ensureUser();
if (await isBanned(user.did)) {
throw new Error("Author is banned");
}
const vote = await getVoteForPost(id);
if (!vote) {
// TODO: Show error notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ export async function commentVoteAction(input: {
rkey: string;
authorDid: DID;
}) {
await ensureUser();
const user = await ensureUser();
if (await isBanned(user.did)) {
throw new Error("Author is banned");
}
await createVote({
subjectAuthorDid: input.authorDid,
subjectCid: input.cid,
Expand Down

0 comments on commit e8af35b

Please sign in to comment.