3

I try to migrate from AWS JavbaScript SDK V2 to V3.

I want to retrieve the user groups a logged-in Cognito user (form an identity pool) belongs to.

In V2, this was as easy as looking in the ["accessToken"].payload['cognito:groups'] element of the sign-in response.

In V3 it's not part of the response. How do I get this piece of information in V3?

HOK
  • 225
  • 1
  • 11

1 Answers1

0

I am using Amplify Auth, so I use the following code:

    const session = await Auth.currentSession();
    let idToken = session.getIdToken();
    console.log(idToken.payload["cognito:groups"]);

You should just switch to "idToken" instead of "accessToken" in the sign-in response, and that should do the trick.

LNI
  • 2,935
  • 2
  • 21
  • 25