File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,8 +4,12 @@ import { User } from '@/models/User';
44import { trackUserRateLimiter } from '@/lib/rate-limit' ;
55
66export async function POST ( req : Request ) {
7- // Get IP for rate limiting
8- const ip = req . headers . get ( 'x-forwarded-for' ) || req . headers . get ( 'x-real-ip' ) || 'unknown' ;
7+ // Get IP for rate limiting.
8+ // x-real-ip is provided by Vercel/Nginx as the true client IP.
9+ // We fall back to the LAST IP in the x-forwarded-for chain, which is appended by the Vercel proxy.
10+ const forwardedFor = req . headers . get ( 'x-forwarded-for' ) ;
11+ const fallbackIp = forwardedFor ? forwardedFor . split ( ',' ) . pop ( ) ?. trim ( ) : 'unknown' ;
12+ const ip = req . headers . get ( 'x-real-ip' ) || fallbackIp || 'unknown' ;
913
1014 if ( ip !== 'unknown' && ! ( await trackUserRateLimiter . check ( ip ) ) ) {
1115 return NextResponse . json (
You can’t perform that action at this time.
0 commit comments