Conversation
There was a problem hiding this comment.
Greptile Summary
This PR adds support for extracting and managing multiple user roles from JWT payloads in the WorkOS AuthKit React SDK. The changes introduce a new roles field alongside the existing single role field to provide more flexible role-based access control.
The implementation follows the established patterns in the codebase:
-
State Management: A new
roles: string[] | nullfield is added to theStateinterface insrc/state.ts, initialized tonullin theinitialStateobject, matching the pattern used by other JWT-derived fields likepermissionsandfeatureFlags. -
JWT Extraction: The
AuthKitProvidercomponent insrc/provider.tsxis updated to extract therolesarray from JWT claims using the same destructuring pattern as other claims. The roles are then included in the session state updates. -
Session Comparison: The session equality check is updated to include
rolescomparison (a.roles === b.roles) to prevent unnecessary re-renders when roles change. -
IDE Configuration: The
.gitignorefile is updated to exclude JetBrains IDE configuration files (.ideadirectory), which is a standard practice for maintaining a clean repository.
This change maintains backward compatibility by preserving the existing single role field while adding the new roles array functionality. The implementation integrates seamlessly with the existing authentication context and state management system, allowing consuming applications to access both individual role and multiple roles as needed.
Confidence score: 5/5
- This PR is safe to merge with minimal risk
- Score reflects simple additive changes that follow established patterns and maintain backward compatibility
- No files require special attention
3 files reviewed, no comments
| isLoading: boolean; | ||
| user: User | null; | ||
| role: string | null; | ||
| roles: string[] | null; |
There was a problem hiding this comment.
Out of curiosity, why not string[] and default to an empty array like permissions and featureFlags?
There was a problem hiding this comment.
It's an optional field in the JWT payload, so I didn't want to default to empty. If users use this to authorize anything, an empty roles array might be different than expected and change the authorization decision. Also felt weird that roles could be null, but roles couldn't
No description provided.