Hi there,
I’m looking for some advice on how to tackle a particular use case I have. I have two Algolia indexes: Categories and Posts.
Any logged in user of my app should be able to search the entire Categories index: this can be achieved using the Search API key that comes by default and all works okay.
The Posts index I want to secure by ensuring that the logged in user can search only their own posts, not the entire index. To do this I added a userId property to the index and generated a secureAPIKey with the filter attribute set:
const publicKey = client.generateSecuredApiKey(SEARCH_KEY, { filters:
userId:${userId} });
The problem I have now is that the filter is also applied to the Categories index, which I verified by making a Postman request:
{
"hits": [],
"nbHits": 0,
"page": 0,
"nbPages": 0,
"hitsPerPage": 20,
"exhaustiveNbHits": true,
"query": "spa",
"params": "query=spa&filters=userId%3Ai3wd8zL3seV0bDhhYSCZecSs9jK2",
"processingTimeMS": 1
}
So my question is: how should approach allowing unrestricted search to one set of indices, but restricted search to another set, using only one API Key? (I assume I shouldn’t be generating keys specifically per index, they should be per user/user session?)
Many thanks,