Last active
July 21, 2020 18:54
-
-
Save stevef/2afa03a34225a2195f9789056957b057 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 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