When I add this code to react, the error appears to be that await is not recognized. The exact error is Property Assignment Expected at the 'await' word
I'm reading the documentation from aws-amplify from here about custom headers https://aws.github.io/aws-amplify/media/api_guide#custom-request-headers .
Here is the code from the index.js (where amplify is configured)
aws_exports.API = {
endpoints:[
{
name: "my_custom_api",
endpoint: "http://localhost:57200/",
custom_header: async() => {
return { (await Auth.currentSession()).idToken.jwtToken }
}
}
]
}
Amplify.configure(aws_exports);
It looks like there is a typo in the documentation. return { (await Auth.currentSession()).idToken.jwtToken }
is invalid syntax, but if you assign that value to the Authorization
key it should work:
async () => {
return { Authorization: (await Auth.currentSession()).idToken.jwtToken };
}