Skip to content

Configure amplify to send IdToken at Gen2

0

With User Pool authentication in Amplify, we want to send the idToken as the authorization header instead of the accessToken. In Amplify Gen1 (React JS), we achieved this successfully, and we've attached the relevant code snippet (indexJS_File.png) for reference.

indexJS_File.png

Now, when implementing the same approach in Amplify Gen2 (React TSX), we are encountering an error.

Could you guide us on the necessary code modifications or configuration changes needed to make this work?

asked 10 months ago42 views
1 Answer
0

Hello,

Thank you for reaching out to us regarding the error you are facing.

To resolve the issue, I have replicated the same at my end and it worked when using the below function:-

Amplify.configure(outputs,
  {
    API:
    {
      GraphQL:
      {
        headers: 
        async () => {
          const session = await fetchAuthSession();
          console.log("id token", session.tokens.idToken)
          return {
                   Authorization: session.tokens.idToken.toString(),
            };
        }
      }
    }
  }
)

You can try using the above function, if in case you are facing any issue please react out to our AWS Amplify support team

AWS
answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.