I'm trying to get the IP address from the client in the firebase function by using javascript . Why do I need IP? To make whitelist IPs that can access my functions.
my goal: access my function by IP address
I tried to use this method but didn't work for me it give me 'undefined' :
exports.getIP = functions.https.onRequest(async (req, res) => {
var call = req.ip
console.log(call);
res.send(call);
});
exports.getIP = functions.https.onRequest(async (req, res) => {
var call = req.headers['x-forwarded-for']
console.log(call);
res.send(call);
});
Here when I call req.headers :