#Getting IP

5 messages · Page 1 of 1 (latest)

atomic flicker
#

What is the best way to get the users IP? Because when I host on Vercel it no longer returns the end-users IP ( when I request ifconfig.me ) I need to get users ip once in my next-auth signIn function and another time in a page function like this:

export default async function Redirect({ params: { code } }: Props) {
  const data = await db.url.findFirst({
    where: {
      code,
    },
  });

  if (!data) return redirect("/error?message=Redirect+url+was+not+found");

  if (!data.active)
    return redirect("/error?message=Redirect+url+has+been+temporally+disabled");

    await db.url.update({
        where: {
            code: code as string
        },
        data: {
            analytics: {
                push: {
                    url: 'ok'
                }
            }
        }
    })

  redirect(data.redirectUrl);
}
fair horizonBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

hardy sable
#

Hey, this code works for me on nextjs 14 and vercel.

function getIpAddress(request: NextRequest) {
  const headers = new Headers(request.headers);

  return headers.get('x-forwarded-for') ?? '0.0.0.0';
}
atomic flicker
#

Thank you! I'm using both methods now and they both get the job done sunglasses_1