Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaumya/a1c7285df97417f6d47b1954cab97ff9 to your computer and use it in GitHub Desktop.
Save isaumya/a1c7285df97417f6d47b1954cab97ff9 to your computer and use it in GitHub Desktop.
Get Cleint IP & IP Details with Firebase Cloud Callable Function

Example Firebase Cloud Function - Callable (not onRequest)

exports.checkReq = functions.region('asia-east2').https.onCall(async (data, { rawRequest }) => {
  try {
    const ip = rawRequest.headers['x-forwarded-for'] || rawRequest.connection.remoteAddress

    const response = await axios.get(
      `http://api.ipstack.com/${ip}?access_key=${IPSTACK_API_KEY}`
    )
    // console.log( rawRequest,ip, response)
    return {
      ip,
      city: response.data.city,
      success: 'yes'
    }
  } catch (error) {
    throw new functions.https.HttpsError(error)
  }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment