Hey guys! Is it possible to proxy instantsearch.js...
# community-help
k
Hey guys! Is it possible to proxy instantsearch.js requests to the Typesense through some extra backend (acting as a proxy between browser and Typesense)? We have two groups of users: 1. regular - can access public issues 2. trusted - should be able to access public + private issues Our threat model is that if the search API key is shared on the frontend (as it currently is), then users who are no longer trusted could still use the known public API key (for private search) to search the collection, even though they should no longer have an access to it. What we would like to do? Instead of having a public key for a separate collection (or two keys with embedded `filter_by` clause to have docs in a single collection), we would like to proxy the requests to the backend first, which can further authorize if user is still a trusted one, and if it can fetch this collection. I understand from docs that TypeSense is specifically designed not to go this route, but is something like this possible at all?
f
Theoretically, using a Typesense-valid API route inside your client config could work, since the Typesense JS library is just a thin wrapper around the API using Axios for requests. And it's what the Adapter relies on for the API requests
k
Well, in our case backend is Atlassian Forge, which means it's not a regular backend API endpoint per-se (more like RPC-style, where we invoke some function on the frontend, which runs some code on the backend). I'm thinking now, that maybe we could use it to generate a short lived search API key for every trusted user, so we could utilize it in the the style typesense was intended for, without having to proxy requests at all. What do you think about this approach?
We are already using similar approach to retrieve public API key, so I think this might work well, except we don't need to recreate public API key in that case per-user. I think I've answered myself with this one.
f
Catering towards Typesense's idioms is best. Short-lived API keys are far better than proxying requests over to a backend service for Auth
👍 1
k
on instantsearch - you can inject your own search client, which can be a proxy. We use that on several solutions with instantsearch
👍 1
k
Thank you Fanis and Klaus! I've decided to go with the short lived API keys. Also, thanks Klaus for providing this detail too, might be useful in the future.