Created
September 13, 2024 11:14
-
-
Save Ebrahim-Ramadan/fb546261e39c6c3289fdd172cef71d91 to your computer and use it in GitHub Desktop.
Geolocation helper function for nextjs server components
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { headers } from "next/headers"; | |
export function geoLocation() { | |
const headersList = headers(); | |
return { | |
ip: headersList.get("x-real-ip"), | |
country: headersList.get("x-vercel-ip-country"), | |
city: headersList.get("x-vercel-ip-city"), | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment