How and Where to store a Secured API Key (for example for Algolia)?

Posted 8 months ago by shadrix

So I'm trying to implement this:

//example from the page
$currentUserID = 1; // Replace by the current user ID

$securedApiKey = \AlgoliaSearch\Client::generateSecuredApiKey(
  'YourSearchOnlyApiKey', // Make sure to use a search key
    'filters' => 'viewable_by:'.$currentUserID

However, since the user is not always logged in I don't have a user id. So my guess is just to take the session id, it should work the same right?

But now I'm curious, where should I put this part of code?

My first thought was in But can it work even though I cache the config?

Should I put it somewhere else?

To fetch the key for the frontend, I'm saving it to window.App.keys

Please sign in or create an account to participate in this conversation.