From 5ed3b60351fa4a4ea0e27687b36e218c61e33e4f Mon Sep 17 00:00:00 2001 From: Chris Bonifacio Date: Thu, 19 Dec 2024 10:49:57 -0500 Subject: [PATCH] add example for accessing user groups from session --- .../user-group-based-data-access/index.mdx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx index 934b3421718..bb3a5ea8b2c 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx @@ -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 + +## Access user groups from the session + + + +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); +``` +