Created
December 16, 2021 21:12
-
-
Save rschwabco/3ea0cb54f43158aabec897789bc3f2de to your computer and use it in GitHub Desktop.
This file contains hidden or 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 [message, setMessage] = useState(false); | |
const accessSensitiveInformation = useCallback(async () => { | |
try { | |
if (!auth.isLoading) { | |
const accessToken = auth.userData?.id_token; | |
const sensitiveInformationURL = `${process.env.REACT_APP_API_ORIGIN}/api/protected`; | |
const sensitiveDataResponse = await fetch(sensitiveInformationURL, { | |
headers: { | |
Authorization: `Bearer ${accessToken}`, | |
}, | |
}); | |
try { | |
const res = await sensitiveDataResponse.json(); | |
setMessage(res.secretMessage); | |
} catch (e) { | |
//In case no access is given, the response will return 403 and not return a JSON response | |
setMessage(sensitiveDataResponse.status); | |
} | |
} | |
} catch (e) { | |
console.log(e.message); | |
} | |
}, [auth.isLoading, auth.userData?.id_token]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment