2
votes

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);
1
I can't say for certain, but to me it looks like there is a typo in the documentation. Have you tried return { Authorization: (await Auth.currentSession()).idToken.jwtToken };? - Tholle
Oh right, that's true. It's compiling now. Thanks - Bryan Stump

1 Answers

2
votes

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 };
}