Published on

How to get Client IP Address in Next.js getServerSideProps

Authors

Here is how to get request IP address in Next.js getServerSideProps

export async function getServerSideProps({ req }) {
  const ip = req.headers["x-real-ip"] || req.headers['x-forwarded-for'] || req.connection.remoteAddress
  return {
    props: {
      ip
    }
  };
}

Happy finding IP-address!