Skip to content

Commit 102741e

Browse files
Access groups example (#8174)
* remove reference of renameModelFields * add example for accessing user groups from session * simplify example and add some spacing * revert change * add back ticks
1 parent a001291 commit 102741e

File tree

1 file changed

+16
-0
lines changed
  • src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access

1 file changed

+16
-0
lines changed

src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx

+16
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,19 @@ By default, `group` authorization leverages Amazon Cognito user pool groups but
168168
- subscriptions are only supported if the user is part of 20 or fewer groups
169169
- you can only authorize 20 or fewer user groups per record
170170
</Callout>
171+
172+
## Access user groups from the session
173+
174+
<InlineFilter filters={["javascript", "angular", "react-native", "react", "nextjs", "vue"]}>
175+
176+
You can access a user's groups from their session using the Auth category:
177+
178+
```ts
179+
import { fetchAuthSession } from 'aws-amplify/auth';
180+
181+
const session = await fetchAuthSession();
182+
const groups = session.tokens.accessToken.payload['cognito:groups'] || [];
183+
184+
console.log('User groups:', groups);
185+
```
186+
</InlineFilter>

0 commit comments

Comments
 (0)