You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am not sure whether this is a bug or not, but I was unable to find the documentation pertaining to react-instantsearch with updating Secured API key.
So, we have implemented SECURED API key to fetch the key with an expiry time from our backend. We are fetching and updating the API key when we get the error : Invalid Application-ID or API key while doing a query to Algolia.
We have insights={true} but we can see that the event analytics is still pointing to the previous incorrect API key. We are getting correct data from the server for Search, but the analytics is getting 401 Unauthorized error.
This is our implementation of updating the key for searchClient
const{ addMiddlewares, error }=useInstantSearch();useEffect(()=>{constmiddleware=({ instantSearchInstance })=>{functionhandleError(searchError){if(searchError.message==="Invalid Application-ID or API key"){CLIENT.setClientApiKey({apiKey: newAPIKey,});instantSearchInstance.refresh();}}return{subscribe(){instantSearchInstance.addListener("error",handleError);},unsubscribe(){instantSearchInstance.removeListener("error",handleError);},};};returnaddMiddlewares(middleware);},[addMiddlewares]);
Also, one more additional question for this implementation:
Since we get the expiry time in our API key, is there a way we can check the expiry before the ALGOLIA query is called? And then can we set the new API key for making the query?
P.S.: In the Codesandbox, I am not fetching a key from backend, but I am just using an incorrect API key at the start. Then, when I get the invalid API key error, I update the API with the corrrect data.
Analytic Events at first will be denied due to incorrect API key, but after updating the API key, it should work properly (the query param with the API key should get updated).
🐛 Current behavior
Hi team
I am not sure whether this is a bug or not, but I was unable to find the documentation pertaining to
react-instantsearch
with updating Secured API key.So, we have implemented SECURED API key to fetch the key with an expiry time from our backend. We are fetching and updating the API key when we get the error : Invalid Application-ID or API key while doing a query to Algolia.
We have
insights={true}
but we can see that the event analytics is still pointing to the previous incorrect API key. We are getting correct data from the server for Search, but the analytics is getting 401 Unauthorized error.This is our implementation of updating the key for
searchClient
Also, one more additional question for this implementation:
Since we get the expiry time in our API key, is there a way we can check the expiry before the ALGOLIA query is called? And then can we set the new API key for making the query?
P.S.: In the Codesandbox, I am not fetching a key from backend, but I am just using an incorrect API key at the start. Then, when I get the invalid API key error, I update the API with the corrrect data.
🔍 Steps to reproduce
Live reproduction
https://codesandbox.io/p/sandbox/mvkzz9
💭 Expected behavior
Analytic Events at first will be denied due to incorrect API key, but after updating the API key, it should work properly (the query param with the API key should get updated).
Package version
"algoliasearch": "^5.11.0", "react-instantsearch": "7.15.5", "react": "^18.3.1", "react-dom": "^18.3.1",
Operating system
MacOs 15.4
Browser
Microsoft Edge Version 134.0.3124.95 (Official build) (arm64)
Code of Conduct
The text was updated successfully, but these errors were encountered: