Created
May 31, 2022 05:07
-
-
Save sourabhbagrecha/f90393ee94aaf39f5da429e164558e12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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