Well, if you often check your public ip address (for example, various plugins for the desktop), then public api usually have a limit on the request interval and can completely ban you for frequent use of the service.
one request every 21 seconds
.
There are two options for the function: with public access and access via token:
- Install the Firebase CLI and log in:
npm install -g firebase-tools
firebase login
- Create Firebase project via CLI or browser:
firebase projects:create
.firebaserc
, or just create project with name public-ip-function
.
"node"
property in functions/package.json
-
Deploy function:
- Public function:
firebase deploy --only functions:publicFunctions
- Auth function:
firebase deploy --only functions:authFunctions
-
Now you can access via link, like this (or just look for it in Firebase Console):
- Public function:
https://us-central1-MY_PROJECT.cloudfunctions.net/getPublicIp
- Auth function:
https://us-central1-MY_PROJECT.cloudfunctions.net/getPublicIpWithAuth?auth=USER_UID
Create user in
Develop > Authentication > Users > Add User
and use his User UID as access token.