For my Cloud Function, I would like to be able to access certain parts of Cloud Firestore as a particular user in Firebase Auth. There are security rules in place, which allows users based on their roles linked to their UUID to perform certain actions on the data. However, when creating a Cloud Function, I cannot figure out how to make a request to the database as an authenticated user.
The code here would completely bypass the security rules set in place (thus defeating the purpose):
admin.initializeApp({
credential: admin.credential.cert({
projectId: '<PROJECT_ID>',
clientEmail: 'foo@<PROJECT_ID>.iam.gserviceaccount.com',
privateKey: '-----BEGIN PRIVATE KEY-----\n<KEY>\n-----END PRIVATE KEY-----\n'
}),
databaseURL: 'https://<DATABASE_NAME>.firebaseio.com'
});
My question is how do I perform actions in a Cloud Function as an authenticated user.