endpoint to index all users, but need to make sure I protect this route later

This commit is contained in:
Arjun Patel
2022-02-02 13:37:11 -08:00
parent 072339c509
commit 4c48ab3a3d
2 changed files with 21 additions and 1 deletions
+2 -1
View File
@@ -17,5 +17,6 @@ exports.agoraToken = agoraToken;
import { inviteUserToTeam } from "./notifications";
exports.inviteUserToTeam = inviteUserToTeam;
import { manageUserIndex } from "./search";
import { manageUserIndex, updateUsersIndexWithAllUsers } from "./search";
exports.manageUserIndex = manageUserIndex;
exports.updateUsersIndexWithAllUsers = updateUsersIndexWithAllUsers;
@@ -1,4 +1,5 @@
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
const config = functions.config().env.algolia;
import algoliasearch from "algoliasearch";
@@ -25,3 +26,21 @@ export const manageUserIndex = functions.firestore
// otherwise, just update the index with new user information
return usersIndex.saveObject({ objectID: objectId, ...document });
});
// TODO: protect this endpoint to avoid infiltratros if they know the endpoint name
export const updateUsersIndexWithAllUsers = functions.https.onRequest(
async (request, response) => {
const snapshot = await admin.firestore().collection("users").get();
var users: {}[] = [];
snapshot.forEach((doc) => {
const currUser = doc.data();
users.push({ objectID: doc.id, ...currUser });
});
await usersIndex.saveObjects(users);
response.send("Completed index all users!");
}
);