Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const ALGOLIA_ID = functions.config().algolia.app_id;
const ALGOLIA_ADMIN_KEY = functions.config().algolia.api_key;
const ALGOLIA_INDEX_NAME = "notes";
const client = algoliasearch(ALGOLIA_ID, ALGOLIA_ADMIN_KEY);
// [END init_algolia]
// Initialize Firestore
const firestoreOptions = {
projectId: process.env.GCLOUD_PROJECT
};
const db = new Firestore(firestoreOptions);
// [START update_index_function]
// Update the search index every time a blog post is written.
exports.onNoteCreated = firestore.document("notes/{noteId}").onCreate(event => {
// Get the note document
const note = event.data.data();
// Add an "objectID" field which Algolia requires
note.objectID = event.params.postId;
// Write to the algolia index
const index = client.initIndex(ALGOLIA_INDEX_NAME);
return index.saveObject(note);
});
// [END update_index_function]
// [START get_firebase_user]
const admin = require("admin");
function getFirebaseUser(req, res, next) {