Skip to content

Commit ed30f99

Browse files
committed
More comments
1 parent 4636d46 commit ed30f99

File tree

1 file changed

+11
-2
lines changed
  • firestore/full-text-search/functions

1 file changed

+11
-2
lines changed

firestore/full-text-search/functions/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,25 @@ app.use(require("cors")({ origin: true }));
9595
// https://gist.github.com/abehaskins/832d6f8665454d0cd99ef08c229afb42
9696
app.use(getFirebaseUser);
9797

98-
// Finally, we'll add a route handler to
98+
// Add a route handler to the app to generate the secured key
9999
app.get("/", (req, res) => {
100+
// Create the params object as described in the Algolia documentation:
101+
// https://www.algolia.com/doc/guides/security/api-keys/#generating-api-keys
100102
const params = {
101-
hitsPerPage: 20,
103+
// This filter ensures that only documents where author == user_id will be readable
102104
filters: `author:${req.user.user_id}`,
105+
// We also proxy the user_id as a unique token for this key.
103106
userToken: req.user.user_id
104107
};
108+
109+
// Call the Algolia API to generate a unique key based on our search key
105110
const key = client.generateSecuredApiKey(ALGOLIA_SEARCH_KEY, params);
111+
112+
// Then return this key as {key: "...key"}
106113
res.json({ key });
107114
});
108115

116+
// Finally, pass our ExpressJS app to Cloud Functions as a function
117+
// called "getSearchKey";
109118
exports.getSearchKey = functions.https.onRequest(app);
110119
// [END get_algolia_user_token]

0 commit comments

Comments
 (0)