Skip to content

Instantly share code, notes, and snippets.

@sourabhbagrecha
Created May 31, 2022 05:07
Show Gist options
  • Save sourabhbagrecha/4047ec71f1f244900c08f20927b9e6c0 to your computer and use it in GitHub Desktop.
Save sourabhbagrecha/4047ec71f1f244900c08f20927b9e6c0 to your computer and use it in GitHub Desktop.
const { useQuery } = require("react-query");
const useAuthedQuery = (...options) => {
const query = useQuery(...options);
if (query?.error?.response?.status === 401) {
// Insert custom access-token refresh logic here. For now, we are
// just refreshing the page here, so as to redirect them to the
// login page since their token is now expired.
window.location.reload();
}
return query;
}
export default useAuthedQuery;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment