Skip to content

Commit

Permalink
add example for accessing user groups from session
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbonifacio committed Dec 19, 2024
1 parent af0b44c commit 5ed3b60
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,18 @@ By default, `group` authorization leverages Amazon Cognito user pool groups but
- subscriptions are only supported if the user is part of 20 or fewer groups
- you can only authorize 20 or fewer user groups per record
</Callout>

## Access user groups from the session

<InlineFilter filters={["javascript", "angular", "react-native", "react", "nextjs", "vue"]}>

You can access a user's groups from their session using the Auth category:

```ts
import { fetchAuthSession } from 'aws-amplify/auth';

const { tokens } = await fetchAuthSession();
const groups = tokens.accessToken.payload['cognito:groups'] || [];
console.log('User groups:', groups);
```
</InlineFilter>

0 comments on commit 5ed3b60

Please sign in to comment.