mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-21 02:07:23 +02:00
🔒️ Rate limit by ip address (#1155)
This commit is contained in:
parent
491af5c71b
commit
f7eda38e0a
6 changed files with 32 additions and 12 deletions
|
@ -21,7 +21,7 @@ export interface TRPCContextParams {
|
|||
*/
|
||||
absoluteUrl: (path?: string) => string;
|
||||
shortUrl: (path?: string) => string;
|
||||
ratelimit: (key: string) => Promise<{ success: boolean }>;
|
||||
ratelimit: () => Promise<{ success: boolean }>;
|
||||
}
|
||||
|
||||
export const createTRPCContext = async (
|
||||
|
|
|
@ -24,14 +24,12 @@ export const auth = router({
|
|||
| { ok: true; token: string }
|
||||
| { ok: false; reason: "userAlreadyExists" | "emailNotAllowed" }
|
||||
> => {
|
||||
if (process.env.KV_REST_API_URL) {
|
||||
const { success } = await ctx.ratelimit(ctx.user.id);
|
||||
if (!success) {
|
||||
throw new TRPCError({
|
||||
code: "TOO_MANY_REQUESTS",
|
||||
message: "Too many requests",
|
||||
});
|
||||
}
|
||||
const { success } = await ctx.ratelimit();
|
||||
if (!success) {
|
||||
throw new TRPCError({
|
||||
code: "TOO_MANY_REQUESTS",
|
||||
message: "Too many requests",
|
||||
});
|
||||
}
|
||||
|
||||
if (ctx.isEmailBlocked?.(input.email)) {
|
||||
|
|
|
@ -64,7 +64,7 @@ export const participants = router({
|
|||
}),
|
||||
)
|
||||
.mutation(async ({ ctx, input: { pollId, votes, name, email } }) => {
|
||||
const { success } = await ctx.ratelimit(ctx.user.id);
|
||||
const { success } = await ctx.ratelimit();
|
||||
|
||||
if (!success) {
|
||||
throw new TRPCError({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue