2

Our users are using custom token authentication. When logging in to our app, the following code is executed:

firebase.auth().signInWithCustomToken(token)

where token is created using com.google.firebase.auth.FirebaseAuth#createCustomToken from Firebase Admin, passing user id.

Then a user is adding some documents in Firestore, using for example:

firebase.firestore()
.collection('users')
.document('someId')
.set({
  some: 'data'
})

I have a Firebase Cloud Function listening to changes in Firestore documents:

const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

// Listen for updates to any `user` document.
exports.testCloudFunction = functions.firestore
.document('users/{documentId}')
.onWrite((event) => {
  // print the id here
});

How can I print the uid of the logged in user that created the Firestore document which triggered my function?

In an answer to similar question about Realtime Database triggered function it's said to use event.auth object, but in my function its value is undefined (may it be an error in my code or is it supposed to be empty?)

Kuba
  • 1,113
  • 10
  • 26
  • 3
    This is currently not possible with Firestore. The team is aware this is in demand. If you would like to file a feature request, that adds weight to the request. https://firebase.google.com/support/contact/bugs-features/ – Doug Stevenson Nov 13 '17 at 18:27
  • @DougStevenson ah that's too bad, thanks for the response. I filed a feature request. – Kuba Nov 13 '17 at 19:06

0 Answers0