Repository navigation
Add Cognito groups to auth context and user profile - #44
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request exposes Cognito group membership (cognito:groups from the ID token) via the app’s auth context and surfaces it in the User Profile modal so group info is available consistently across the UI (and for future RBAC usage).
Changes:
- Adds
groups: string[]to theAuthContextValueand auth provider state, populated fromfetchAuthSession()during initialization. - Normalizes Cognito’s autogenerated federated-IDP group names into friendlier labels before storing them in context.
- Displays groups in the User Profile modal and wires the prop through
UserMenu; updates existing layout tests’ auth mocks.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/context/auth-context.ts | Extends the auth context value type to include groups: string[]. |
| src/context/AmplifyAuthProvider.tsx | Fetches auth session alongside user attributes, extracts/normalizes cognito:groups, and stores it in provider state/context. |
| src/components/layout/header/UserProfileModal.tsx | Adds optional groups prop and renders a Groups section with pill badges when non-empty. |
| src/components/layout/header/UserMenu.tsx | Passes groups from useAuthContext() into UserProfileModal. |
| src/components/layout/tests/Header.test.tsx | Updates AuthContextValue test mock to include groups. |
| src/components/layout/tests/app-shell.test.tsx | Updates AuthContextValue test mock to include groups. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+131
to
+151
| {/* Groups */} | ||
| {groups.length > 0 && ( | ||
| <div> | ||
| <p className='mb-2 text-[11px] font-semibold tracking-wider text-slate-400 uppercase dark:text-neutral-500'> | ||
| Groups | ||
| </p> | ||
| <div className='flex items-start gap-3 rounded-lg border border-slate-200 px-4 py-3 dark:border-[#2d3540]'> | ||
| <Users className='mt-0.5 h-4 w-4 shrink-0 text-slate-400 dark:text-[#9dabb9]' /> | ||
| <div className='flex min-w-0 flex-1 flex-wrap gap-1.5'> | ||
| {groups.map((g) => ( | ||
| <span | ||
| key={g} | ||
| className='inline-flex items-center rounded-full bg-slate-100 px-2.5 py-0.5 text-[11px] font-medium text-slate-700 dark:bg-[#2d3540] dark:text-slate-300' | ||
| > | ||
| {g} | ||
| </span> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| )} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Surfaces the
cognito:groupsJWT claim in the auth context and displays it in the User Profile modal.Why
Group membership was only accessible by manually decoding the JWT token. Exposing it via the auth context makes it available app-wide for consistent display and future RBAC use.
Changes
Auth provider (
AmplifyAuthProvider.tsx)fetchAuthSession()in parallel withfetchUserAttributes()during auth initialisation (reads from local cache — no extra network round-trip)cognito:groupsfrom the ID token payloadap-southeast-2_iWOHnsurL_Google→Google (default)) before storing in context, so all consumers receive friendly namesAuth context (
auth-context.ts)groups: string[]toAuthContextValueUser Profile modal (
UserProfileModal.tsx)groupsprop and renders a Groups section as pill badges (hidden when empty)User menu (
UserMenu.tsx)groupsfromuseAuthContext()toUserProfileModalNotes
/^[a-z]+-[a-z]+-\d+_[A-Za-z0-9]+_(\w+)$/— matches the{region}_{poolId}_{Provider}Cognito pattern and renders the provider suffix with(default)labeladmin,bioinfo,curators) pass through unchanged