Skip to content

Commit

Permalink
Access groups example (#8174)
Browse files Browse the repository at this point in the history
* remove reference of renameModelFields

* add example for accessing user groups from session

* simplify example and add some spacing

* revert change

* add back ticks
  • Loading branch information
chrisbonifacio authored Dec 23, 2024
1 parent a001291 commit 102741e
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,19 @@ 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 session = await fetchAuthSession();
const groups = session.tokens.accessToken.payload['cognito:groups'] || [];

console.log('User groups:', groups);
```
</InlineFilter>

0 comments on commit 102741e

Please sign in to comment.