Skip to content

Instantly share code, notes, and snippets.

@schmidt-sebastian
Created October 17, 2018 20:40
Show Gist options
  • Save schmidt-sebastian/0be7957831f5df6506882a17aa495632 to your computer and use it in GitHub Desktop.
Save schmidt-sebastian/0be7957831f5df6506882a17aa495632 to your computer and use it in GitHub Desktop.
Activity Log Sample with Firestore + Cloud Functions Trigger
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const firestore = admin.firestore();
exports.activityLog = functions.firestore
.document('privacy/{uid}').onWrite(snap => {
const uid = context.params.uid;
const settings = snap.data();
settings['udpate_time'] =
admin.firestore.FieldValue.serverTimestamp();
firestore.collection(
`activity_log/${uid}/entries`
).add(settings);
match /activity_log/{uid} {
allow create: if request.auth.uid == uid;
allow update: if false;
allow delete: if false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment