aws-amplify / docs

AWS Amplify Framework Documentation
https://docs.amplify.aws
Apache License 2.0
483 stars 1.04k forks source link

Bug in calling Auth Admin queries API #6945

Open tunglh-asilla opened 8 months ago

tunglh-asilla commented 8 months ago

In this doc https://docs.amplify.aws/javascript/build-a-backend/auth/admin-actions/, the guide shows that calling API as below:

async function listEditors(limit){
  let apiName = 'AdminQueries';
  let path = '/listUsersInGroup';
  let options = { 
      queryStringParameters: {
        "groupname": "Editors",
        "limit": limit,
      },
      headers: {
        'Content-Type' : 'application/json',
        Authorization: `${(await fetchAuthSession()).tokens.accessToken.payload}`
      }
  }
  const response = await get({apiName, path, options});
  return response;
}

But I think it missed Bearer keyword, specifically

Authorization: `Bearer ${(await fetchAuthSession()).tokens.accessToken.payload}`

And, please add tutorial to change auth function role from local env

sidshrivastav commented 7 months ago

Try this:

Authorization: Bearer ${(await fetchAuthSession())?.tokens?.accessToken}

It worked for me.

SLYtiger16 commented 7 months ago

It took me awhile to find this in the webs. The docs page and tutorials definitely needs to be updated, the "copy" code is incorrect.

suryaishnavi commented 5 months ago

"I've been working on setting up admin actions in my React app for the past few days. I used some example code from the documentation, but I'm getting a CORS error. I tried testing a method from API Gateway, but I'm getting a 401 unauthorized error. Can you suggest how I can solve these issues?"

iykelaw commented 5 months ago

The doc hasn't been updated yet, took me a whole day to find this chat after so much searching, deleting, and recreating the AdminQueries and this was the only issue and it worked after updating to:

Authorization: Bearer ${(await fetchAuthSession())?.tokens?.accessToken}

Thanks, guys