Are there Algolia instantsearch callbacks for invalid token errors?

I am building a web application with a Ruby on Rails backend and a ReactJS interface. I use Algolia instantsearch.js for the search page, and I want to use custom keys to create a key when the page loads and removes access for this key when the user logs out. I also want them to expire in 2 hours.

All this goes well, but sometimes the newly created user key does not gain access to the index before the instantsearch client tries to connect (strange, right?), Resulting in the initial "search" fail, the wrong key error returned by the Algolia server, and empty results section. Enter the search in the panel immediately after that, and the key will be accepted.

I decided that when the wrong key error returns, I would like the client to stop for a moment and try again. If this fails, I want the error message to appear to the user. This should also solve the issue of expiration while the user is still using it - the message may simply ask the user to refresh the page, avoiding the confusion of a non-responsive application.

Is there a way to do this with instantsearch? In a regular Algolia search, you can add callbacks or specify the following:

index.search({
  filters: 'smartphone AND retina' // smartphone AND retina
}, function searchDone(err, content) {
  if (err) {
    console.error(err);
    return;
  }

  console.log(content);
});

But since instantsearch should "just work", it looks like I have no control over the search function.

SearchResults , , , , . , .

, render, , , , .

+4
1

add_user_key , , . .

, API- , get_user_key_acl, 200 HTTP-.

secured_api_keys.
Algolia Secured API Keys API . , API ( ), , , API , , .

+6

Source: https://habr.com/ru/post/1658042/


All Articles