2

I am trying to write on firebase function some data to DB when some http triggers ,my issue I didn't find any examples how is it possible to do without admin permission because I still want firebase rules to be taken...

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Vitaly Menchikovsky
  • 7,684
  • 17
  • 57
  • 89

2 Answers2

3

You're looking for event.data.ref. From the reference documentation:

Returns a Reference to the Database location where the triggering write occurred. This Reference has the same end-user permissions as the client that did the write. So, if an unauthenticated client did the write, this Reference is unauthenticated. If the client that did the write is authenticated as a certain Firebase Auth user, this Reference is authenticated as that same user.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • is it possible to login user by email only from function in order to be strict ? – Vitaly Menchikovsky Jun 19 '17 at 06:47
  • event.data.ref is already authenticated to the user the performed the write that triggered the event. Are you saying you want a different user than that? FYI it might actually be easier not to use security rules and instead manage everything in Cloud Functions code. – Doug Stevenson Jun 20 '17 at 02:03
  • If you want to impersonate a different user than the one that triggered the write, you could pass in their uid as shown in this section in the documentation. But as Doug commented, that is quite an uncommon use-case – Frank van Puffelen Jun 25 '17 at 15:07
  • There doesn't seem to be an *event* object on a http-trigger (only *req* and *res*). @FrankvanPuffelen are you missing a link in your comment above about the possibility to pass a uid? – Simon Kibsgård Jul 24 '17 at 14:46
1

It should be noted that user-scoped references are no longer available as shown here since version 1.0 of the functions SDK.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441