Files
zeekayandHanzo Dev 8b3607cd0d geo: read the visitor's location from our own edge
Every view was being recorded as 127.0.0.1 in Munich. The IP and geo came from
@vercel/functions behind `process.env.VERCEL === "1"`, and this app runs on
Kubernetes — so the branch was always false and every call took the
LOCALHOST_GEO_DATA placeholder. Analytics has been recording a fixed German
address for every visitor.

Cloudflare fronts dataroom.hanzo.ai (and every hanzo.ai host), so the real values
already arrive as request headers: cf-connecting-ip, cf-ipcountry, and — when the
zone's visitor-location transform is on — cf-ipcity, cf-region, cf-iplatitude,
cf-iplongitude, cf-ipcontinent. lib/utils/geo.ts now reads those. No SDK, no
platform binding, and each optional field degrades on its own so a missing city
never costs us the country.

`cf-connecting-ip` is the one a client cannot forge — Cloudflare rewrites it at
the edge. x-forwarded-for is only the fallback for a request that did not come
through it, and only its FIRST entry: the rest are proxies, and anything a client
sent is appended rather than prepended.

This also repairs rate limiting. `send-otp:`, `verify-otp:` and `verify-email:`
key their limiter on the caller's address, and off Vercel that address was
undefined — so every caller shared one bucket and the limit was effectively
global.

Verified with npx tsc --noEmit: 100 errors before and after, compared by
file+code+message rather than line, since inserting imports shifts line numbers
and would otherwise report unchanged errors as new.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-09 10:27:33 -07:00
..