From ad34e6a3e43ff94bb54eb40cd45a76c371aa2e99 Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Sat, 22 Jun 2024 16:02:12 +0200 Subject: [PATCH] fix(api): :bug: get correct client ip even through server proxy --- routes/api/magiclink/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routes/api/magiclink/index.ts b/routes/api/magiclink/index.ts index 25734ba..70390ac 100644 --- a/routes/api/magiclink/index.ts +++ b/routes/api/magiclink/index.ts @@ -51,7 +51,9 @@ export const handler: SessionHandlers = { // send mail to user try { if (user) { - const ip = ctx.remoteAddr.hostname + // Get user ip through proxy else from tcp connection + const ip = request.headers.get('X-FORWARDED-FOR') ?? + ctx.remoteAddr.hostname const device = request.headers.get('Sec-Ch-Ua-Platform') ?? undefined await sendMagicLink(user, { device, ip, endpoint })