Deploying authenticated cloud function using firebase - firebase

I want to uncheck "Allow unauthenticated invocations" in my newly created cloud function. I can do it from console. But i want it to be done via command prompt(firebase deploy). I am looking out for some field/attribute which i can add while deploying the cloud function. Please help me with this issue.

Unfortunately, at the time of writing, the public invocation policy is hard coded into the firebase-tools CLI.
The code in question can be found in firebase-tools/src/deploy/functions/release.js.

Related

Firebase cloud functions init not working

I want to use Firebase cloud functions but when I try to init exists project I get error.
This is the error "Error: HTTP Error: 403, The caller does not have permission"
I created project before and then I moved project folder. When I had tried deploy, it wasn't work. I don't remember which error I got. And then I tried init same project but I got this error.
I tried logout and login again but it wasn't work.
I deleted "firebase-tools" but it wasn't work too.
And after I tried on different computer and I got same error.
And also I have Firebase Admin permission.
The firebase init command initializes/enables the project to use Cloud Functions for Firebase. Owners or Editors should use this command. Owners/Editors have higher permissions which allows APIs to be enabled (e.g. allowing the project to create VMs, Cloud Functions, or create a NoSQL Database).
Therefore I think you should perform this operation with Owner/Editor role.
You need to have Owner or Editor IAM permission on the GCP project to use firebase init command.
The firebase init command initializes/enables the project to use Cloud Functions/Hosting for Firebase. Owners/Editors have higher permissions that allow APIs to be enabled etc.
it is a first-time task when you starting the development, and then init command can be avoided if you have set up your cloud functions code in VCS for multiple developers or you.
i.e, Usually after writing code, you will replicate the project to other developers, who will then also write code and use firebase use yourprojectid further.

Can you give blanket public access to users in a Firebase project?

I have an open-source project that uses two separate Firebase projects for a test environment and the production one.
Ultimately, I want to have other developers be able to pull down the project and actually be able to run it WITHOUT me needing to give each individual developer access.
I see a number of solutions in this question: How to add collaborators to a Firebase app?. Those all seem to require each person's email.
I understand why it maybe isn't a thing, but I am wondering if there is a way to just give access to everyone for only the test project so that contributing is super low-friction. Something similar to Firestore database rules that allow read/write in a public fashion to get started for testing.
I've tried making a new IAM account in the Google Cloud Console, and I think that partially worked for the Firebase Cloud Functions access to Admin SDK, but my collaborators get hung up trying to run firebase use <test-firebase-project> saying that they don't have access.
I see a lot of other config options for IAM, but nothing sticking out to me for this public access scenario.
Can anyone confirm this either is or isn't a thing?
Thanks!
EDIT
To add some more detail to my project...
I am using Authentication, Firestore, and Cloud Functions. The only js package I will use is the Auth one, which will be loaded from a CDN (so I believe that doesn't apply to my question).
I want to give access to people to run the Cloud Functions locally. There is a pre-build step that I have made in vanilla Node that calls a Cloud Function (running locally), which uses the Firebase Admin SDK to call my Firestore database. I then write that response to a JSON file that my front end uses.
When my collaborators pull down the project, and install the Firebase CLI, when they try to serve the Cloud Functions locally, they get hit with a "no access" type of error. I was trying to resolve this by adding a service account into the /functions directory, but apparently that didn't help.
My collaborators don't need access to the console at all. I basically just need them to be able to run the Cloud Function locally (and make sure they can't access my production Firebase project).
I am happy to add more detail, but I kind of feel like I am just rambling. Thanks again.
There is no way to grant everyone contributor access to your Firebase console. You will either have add each individual user, or create your own dashboard that uses the API to show the relevant data.

How to Run Admin functions on Firebase

I'm trying to create a function to delete all users from the Database and write it on index.ts file and deploy it. Now, how can I run it?? I don't want my clients to run it from their mobile app, I need some admin tool to run the management functions. When I see cloud functions on Firebase console there's no option to run the functions, just to view their logs.
Cloud Functions isn't for running one-time scripts. You should do that on your local machine. Cloud Functions is for running code that responds to HTTP requests, or events that occur within other products in your project.
You may want to read this article: https://firebase.googleblog.com/2017/03/how-to-schedule-cron-jobs-with-cloud.html - it suggests using App Engine cron job for that purpose. Relevant project on github: https://github.com/FirebaseExtended/functions-cron
Also there's an example on similar topic in Firebase docs: https://github.com/firebase/functions-samples/tree/master/delete-unused-accounts-cron

Cloud Functions deployment failiure from Firebase

I seem to be unable to deploy Google Cloud Functions successfully.
I have created a project on Google Cloud Platform and then proceeded to link it to Firebase via the Firebase console. I select ADD PROJECT and Add Firebase to an existing project. Everything seems to link.
When I try to deploy a cloud function (the simple helloWorld that comes with installing firebase-tools) I keep getting deployment errors. This also happens when trying to deploy functions from Google Cloud Functions dashboard as well.
The error is something aboud setting up the environment.
After ttrying to rename the function to something else, I seem to have luck with deploying but then the function but there is a communication error Function load error: Error: cannot communicate with function.
I am unable to deploy functions on two of my projects, and firebase has been acting very strangely in the last few days, so can somebody please tell me if I am doing something wrong or is it a Firebase glitch
Maybe because there is an outage starting from early this morning. Check status here: https://status.firebase.google.com

Debugging Firebase Cloud Functions using Stackdriver

I am following this doc to try to debug my firebase cloud function: https://cloud.google.com/functions/docs/monitoring/debugging
First of all the
The require line given in the doc was wrong so I changed it to this to make it compile:
require('#google-cloud/debug-agent').start();
Also after implementing this and deploying the functions using firebase deploy --only functions there is no code in stack drive debug view. Any idea how to make this work?
Thanks :)
Currently, Cloud Functions for Firebase do not share their code with Stackdriver automatically. You'll need to source your code via Github, Bitbucket, or a Google Cloud Source Repository.
While debugging Cloud Functions for Firebase please refer to our documentation. We'll make sure to note any differences between the environments.

Resources