I am following the Firebase tutorial on how to implement Algolia with Firebase: https://firebase.google.com/docs/firestore/solutions/search
I am currently stuck on the indexing part of the tutorial as I have errors coming from the firebase cloud-functions logs.
The error is: TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "x-algolia-api-key"
How can I fix this error?
Here is my code
const functions = require('firebase-functions');
const algoliasearch = require("algoliasearch");
const ALGOLIA_ID = functions.config().algolia.app_id;
const ALGOLIA_ADMIN_KEY = functions.config().algolia.api_key;
const ALGOLIA_SEARCH_KEY = functions.config().algolia.search_key;
const ALGOLIA_INDEX_NAME = 'users';
const client = algoliasearch(ALGOLIA_ID, ALGOLIA_ADMIN_KEY);
// Update the search index every time a blog post is written.
exports.onUserCreated = functions.firestore.document('path').onCreate((snap, context) => {
// Get the note document
const user = snap.data();
// Add an 'objectID' field which Algolia requires
user.objectID = snap.id;
console.log(user.objectID)
// Write to the algolia index
const index = client.initIndex(ALGOLIA_INDEX_NAME);
return index.saveObject(user);
});