Next.js Discord

Discord Forum

How to get user IP from an application in Vercel

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
Hi!

I want to get user IP when it submitted a form.

I tried:

- x-real-ip
- x-forwarded-for
- and a lib 'request-ip';

Ref:

https://vercel.com/docs/edge-network/headers#x-forwarded-for

5 Replies

Sun bearOP
I tried it
check and try my poc at
https://github.com/tfutada/zenn-nextjs/blob/main/middleware.ts

notice that you cannot get real client ips if the user are behind vpn or forward proxy like Zscaler. Plus, if you have a reverse proxy in front of Vercel, the ip woule be the reverse proxy instead of user's IP.
IP are actuallly passed by layer 7, http protocol instead of layer 3 IP protocol.
plus it is good to know, Vercel Edge Runtime runs on Cloudflare Worker, so IPs are passed via Cloudflare edge, i guess.