Skip to content

Instantly share code, notes, and snippets.

@sourabhbagrecha
Created May 31, 2022 05:07
Show Gist options
  • Save sourabhbagrecha/f90393ee94aaf39f5da429e164558e12 to your computer and use it in GitHub Desktop.
Save sourabhbagrecha/f90393ee94aaf39f5da429e164558e12 to your computer and use it in GitHub Desktop.
const { useMutation } = require("react-query");
const useAuthedMutation = (...options) => {
const mutation = useMutation(...options);
if (mutation?.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 mutation;
}
export default useAuthedMutation;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment