Skip to content

Instantly share code, notes, and snippets.

@stevef
Last active July 21, 2020 18:54
Show Gist options
  • Save stevef/2afa03a34225a2195f9789056957b057 to your computer and use it in GitHub Desktop.
Save stevef/2afa03a34225a2195f9789056957b057 to your computer and use it in GitHub Desktop.
const FetchProvider: React.FunctionComponent<React.ReactNode> = ({ children }) => {
const [accessToken, setAccessToken] = useState<string>();
const { getAccessTokenSilently } = useAuth0();
const getAccessToken = useCallback(async () => {
try {
const token = await getAccessTokenSilently();
console.log(`Setting accessToken: ${token}`);
setAccessToken(token);
setTokenToAxios(token);
setLocalStorageToken(token);
} catch (err) {
// TODO: Handle error case here
console.log(err);
}
}, [getAccessTokenSilently]); // is this dependency necessary?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment