This commit is contained in:
2025-12-26 20:54:20 +01:00
parent 904feb41b8
commit 6389be4f0c
26 changed files with 745 additions and 195 deletions

View File

@@ -1,8 +1,11 @@
import { assertKvConfiguredInProduction, isKvConfigured, isProductionEnvironment } from './config/env';
const RATE_LIMIT_WINDOW = 60 * 60 * 1000; // 1 hour in milliseconds
const MAX_REQUESTS_PER_WINDOW = 5;
const RATE_LIMIT_PREFIX = 'ratelimit:signup:';
const isDev = !process.env.KV_REST_API_URL;
// Dev fallback: only allowed outside production.
const isDev = !isProductionEnvironment() && !isKvConfigured();
// In-memory fallback for development
const devRateLimits = new Map<string, { count: number; resetAt: number }>();
@@ -49,6 +52,8 @@ export async function checkRateLimit(identifier: string): Promise<{
}
// Production: Use Vercel KV
assertKvConfiguredInProduction();
const { kv } = await import('@vercel/kv');
const key = `${RATE_LIMIT_PREFIX}${identifier}`;