Algolia backend search or frontend search when an user ID is involved

There is a baked-in way to add user-based security for record access control.

You need to generate ephemeral API keys with filters hard coded. The end user cannot alter those filters to get around the security. When a user comes through your login flow, the backend generates this key with the appropriate filters (e.g. 'filters' => visible_by:group/'.$currentGroupId.' OR visible_by:group/Everybody' and passes it to the front end in places of the search-only API key.

Your records will need to include a matching attribute for the filter (visible_by in this case) with the appropriate values.

You can read more about it here:https://www.algolia.com/doc/guides/security/api-keys/how-to/user-restricted-access-to-data/#generating-a-secured-api-key