mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-30 02:36:30 +02:00
🔒️ Rate limit comments (#1372)
This commit is contained in:
parent
6cfb56d4bc
commit
251ee76979
2 changed files with 16 additions and 8 deletions
|
@ -15,6 +15,7 @@ import {
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@rallly/ui/dropdown-menu";
|
} from "@rallly/ui/dropdown-menu";
|
||||||
|
import { useToast } from "@rallly/ui/hooks/use-toast";
|
||||||
import { Icon } from "@rallly/ui/icon";
|
import { Icon } from "@rallly/ui/icon";
|
||||||
import { Input } from "@rallly/ui/input";
|
import { Input } from "@rallly/ui/input";
|
||||||
import { Textarea } from "@rallly/ui/textarea";
|
import { Textarea } from "@rallly/ui/textarea";
|
||||||
|
@ -77,13 +78,6 @@ function NewCommentForm({
|
||||||
|
|
||||||
const queryClient = trpc.useUtils();
|
const queryClient = trpc.useUtils();
|
||||||
|
|
||||||
const addComment = trpc.polls.comments.add.useMutation({
|
|
||||||
onSuccess: () => {
|
|
||||||
queryClient.polls.comments.invalidate();
|
|
||||||
posthog?.capture("created comment");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const session = useUser();
|
const session = useUser();
|
||||||
|
|
||||||
const { register, reset, control, handleSubmit, formState } =
|
const { register, reset, control, handleSubmit, formState } =
|
||||||
|
@ -93,7 +87,20 @@ function NewCommentForm({
|
||||||
content: "",
|
content: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const { toast } = useToast();
|
||||||
|
|
||||||
|
const addComment = trpc.polls.comments.add.useMutation({
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.polls.comments.invalidate();
|
||||||
|
posthog?.capture("created comment");
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: error.message,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
className="w-full space-y-2.5"
|
className="w-full space-y-2.5"
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { absoluteUrl } from "@/utils/absolute-url";
|
||||||
import { getEmailClient } from "@/utils/emails";
|
import { getEmailClient } from "@/utils/emails";
|
||||||
import { createToken } from "@/utils/session";
|
import { createToken } from "@/utils/session";
|
||||||
|
|
||||||
import { publicProcedure, router } from "../../trpc";
|
import { publicProcedure, rateLimitMiddleware, router } from "../../trpc";
|
||||||
import { DisableNotificationsPayload } from "../../types";
|
import { DisableNotificationsPayload } from "../../types";
|
||||||
|
|
||||||
export const comments = router({
|
export const comments = router({
|
||||||
|
@ -27,6 +27,7 @@ export const comments = router({
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
add: publicProcedure
|
add: publicProcedure
|
||||||
|
.use(rateLimitMiddleware)
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
pollId: z.string(),
|
pollId: z.string(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue