File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
firestore/full-text-search/functions Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -95,16 +95,25 @@ app.use(require("cors")({ origin: true }));
95
95
// https://gist.github.com/abehaskins/832d6f8665454d0cd99ef08c229afb42
96
96
app . use ( getFirebaseUser ) ;
97
97
98
- // Finally, we'll add a route handler to
98
+ // Add a route handler to the app to generate the secured key
99
99
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
100
102
const params = {
101
- hitsPerPage : 20 ,
103
+ // This filter ensures that only documents where author == user_id will be readable
102
104
filters : `author:${ req . user . user_id } ` ,
105
+ // We also proxy the user_id as a unique token for this key.
103
106
userToken : req . user . user_id
104
107
} ;
108
+
109
+ // Call the Algolia API to generate a unique key based on our search key
105
110
const key = client . generateSecuredApiKey ( ALGOLIA_SEARCH_KEY , params ) ;
111
+
112
+ // Then return this key as {key: "...key"}
106
113
res . json ( { key } ) ;
107
114
} ) ;
108
115
116
+ // Finally, pass our ExpressJS app to Cloud Functions as a function
117
+ // called "getSearchKey";
109
118
exports . getSearchKey = functions . https . onRequest ( app ) ;
110
119
// [END get_algolia_user_token]
You can’t perform that action at this time.
0 commit comments