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?)