-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
AuthRelated to Auth components/categoryRelated to Auth components/categoryquestionGeneral questionGeneral question
Description
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
CDK
Environment information
Details
# Put output below this line
System:
OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13900K
Memory: 12.47 GB / 15.50 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
Yarn: 1.22.21 - ~/.nvm/versions/node/v20.9.0/bin/yarn
npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
pnpm: 8.15.1 - ~/.nvm/versions/node/v20.9.0/bin/pnpm
npmPackages:
@tsconfig/node18: ^18.2.2 => 18.2.2
aws-cdk-lib: 2.124.0 => 2.124.0
constructs: 10.3.0 => 10.3.0
sst: ^2.40.3 => 2.40.3
typescript: ^5.3.3 => 5.3.3
npmGlobalPackages:
corepack: 0.20.0
npm: 10.1.0
Describe the bug
When using fetchAuthSession to retrieve the JWT payload of a signed in user, i can get the payload by doing:
fetchAuthSession().then((session): void => {
const token = session?.tokens?.idToken;
if (!token) {
console.log("No token found");
return;
}
const payload = token.payload;
However, all of my users will be assigned to some cognito user group, so I would expect the type of payload to contain cognito:groups, but it does not:
interface JwtPayloadStandardFields {
exp?: number;
iss?: string;
aud?: string | string[];
nbf?: number;
iat?: number;
scope?: string;
jti?: string;
sub?: string;
cognito:groups?: string[]; <--- THIS IS MISSING
}
When i console log my payload it shows this:

And in fact, there is no scope as well, why is that?
Expected behavior
The types for JwtPayloadStandardFields should contain cognito:groups, especially since the authorized user is being fetched by cognito which inherently supports groups.
Reproduction steps
- Start up a basic amplify app with auth
- Add custom user pool groups like
AdminorSuperUser - Attach the
AuthenticatorHOC to the root of the app - Create a user and assign a cognito user pool group to that user
- Fetch and console log the
idTokenpayload as so:
import { fetchAuthSession} from "aws-amplify/auth";
...
useEffect(() => {
fetchAuthSession().then((session): void => {
const token = session?.tokens?.idToken;
if (!token) {
console.log("No token found");
return;
}
const payload = token.payload;
if (!payload) {
console.log("No payload found");
return;
}
console.log("Payload found", payload); <--- shows cognito:groups but types does not contain that
});
}, []);
Code Snippet
// Put your code below this line.Log output
Details
// Put your logs below this line
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
Metadata
Metadata
Assignees
Labels
AuthRelated to Auth components/categoryRelated to Auth components/categoryquestionGeneral questionGeneral question