0

First of all, I am starting with Firebase (web) so please let me know if I have misunderstood Firebase concepts. I need to allow only a function to write to the Firebase database. I have read this post and other examples, that are about how to use databaseAuthVariableOverride to add to Firebase configuration a variable that can be used inside the rule to validate the Firebase function write access, that's ok, but my problem with this approach is that seems that the Firebase function is called after is initialized Firebase before and I need to add this variable inside the Firebase function, and when I a do that (add the variable and initialize Firebase inside the Firebase function) this error appears:

The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.

(Please note that the function is related with the same project)

So, I want to know how to only allow to the Function to write when Firebase is already initialized (please let me know if I misunderstood the Firebase life cycle). I must to say that I can not to add the variable at client side for security reasons, and seems that is from the client that Firebase is initialized for first time.

Community
  • 1
  • 1
moonw
  • 372
  • 2
  • 15
  • Hi. Is this similar to your [other post](http://stackoverflow.com/q/43642900/4625829)? – AL. Apr 27 '17 at 02:22
  • Is about same issue, the other question was made after this question, the other question is a general text, without details for if is more a general scenario or is easy to the people recognize the case and answer the question. I put the answer on both scenarios. do you think that this question must be deleted? – moonw Apr 27 '17 at 13:36
  • Hi moonw. If it's the same post, I would suggest merging it (deleting one and keeping the other, while having the details from both combined). Cheers! :) – AL. Apr 27 '17 at 15:35

1 Answers1

0

Seems that there is a misunderstood about Firebase Functions and Cloud Functions (the error message is because is used code for a Cloud Function within a Firebase Function), but anyway the answer of this question is that you can use adminRef instead ref in the code of the function that will write the data on Firebase database:

event.data.adminRef instead event.data.ref

this will give you full read and write access instead of end-user access.

moonw
  • 372
  • 2
  • 15