docs icon indicating copy to clipboard operation
docs copied to clipboard

Bug in calling Auth Admin queries API

Open tunglh-asilla opened this issue 1 year ago • 4 comments

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

tunglh-asilla avatar Feb 22 '24 03:02 tunglh-asilla

Try this:

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

It worked for me.

sidshrivastav avatar Mar 02 '24 07:03 sidshrivastav

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.

SLYtiger16 avatar Mar 21 '24 23:03 SLYtiger16

"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?"

suryaishnavi avatar May 03 '24 13:05 suryaishnavi

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

iykelaw avatar May 08 '24 14:05 iykelaw