0

I have a trigger that calls onWrite. I need to get the uid of the user who caused this trigger in firestore. Is this possible?

exports.onEventsWrite = functions.firestore
  .document('events/{eventId}')
  .onWrite(event => {
    // Need the uid
}
Tometoyou
  • 7,792
  • 12
  • 62
  • 108
  • check this https://stackoverflow.com/questions/42750060/getting-the-user-id-from-a-database-trigger-in-cloud-functions-for-firebase – Peter Haddad Feb 21 '18 at 10:37
  • @PeterHaddad Thanks but I think that is for a real time database trigger rather than a firestore one – Tometoyou Feb 21 '18 at 10:45
  • Its the same both db and firestore use `onWrite()` this for firestore: https://firebase.google.com/docs/functions/firestore-events and this is for firebase: https://firebase.google.com/docs/functions/database-events. Both also use event.data, but it seems firestore uses `data()` to return the type and realtime database uses `val()` to return the type. Do you have the uid inside events? – Peter Haddad Feb 21 '18 at 10:49
  • The information on who triggered a function isn't available for Firestore at the moment. Consider adding it to the event itself or to the path that you trigger on. – Frank van Puffelen Feb 21 '18 at 15:28

0 Answers0