-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
types: fix permission types and userOrg default value #228
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes in this pull request involve modifications to the Changes
Possibly related PRs
Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
types.d.tsOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the plugin "eslint-plugin-jest". (The package "eslint-plugin-jest" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
The plugin "eslint-plugin-jest" was referenced from the config file in ".eslintrc.json". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- src/config/index.ts (2 hunks)
- types.d.ts (2 hunks)
🔇 Additional comments (6)
src/config/index.ts (5)
3-3
: LGTM: Clean type import additionThe KindeState type import is properly added, improving type safety.
5-5
: LGTM: Proper type annotation addedThe explicit KindeState type annotation improves type safety and code maintainability.
28-33
: LGTM: Consistent token property additionsThe new token-related properties and methods follow a consistent pattern:
- All properties initialized as null
- Corresponding getter methods returning null
- Clear naming convention
13-13
:⚠️ Potential issueBreaking Change: userOrganizations default value
Changing
userOrganizations
from[]
tonull
is a breaking change that could affect null checks in consuming code. Consider:
- Adding a migration guide
- Documenting this change in the changelog
#!/bin/bash # Search for userOrganizations usage patterns echo "Checking userOrganizations access patterns:" rg -A 2 'userOrganizations\.' --type typescript echo -e "\nChecking null checks on userOrganizations:" rg -A 2 'userOrganizations(\s+)?(!=|==|===|!==)(\s+)?(null|\[\])' --type typescript
11-11
: Verify permission type consistencyThe permission initialization and getter return type align with the updated KindeState type. Let's verify this change is consistent across the codebase.
Also applies to: 20-20
✅ Verification successful
Let me try a different approach to search for permission-related patterns in the codebase. The previous command had issues with the TypeScript file type recognition, so I'm using more generic ripgrep patterns without file type filters.
Permission type initialization is consistent across the codebase
The empty array initialization for permissions is consistent with the codebase's type definitions and usage patterns:
- Type definitions in
types.d.ts
showpermissions: KindePermissions | []
in the state type- Initial states in both
src/config/index.ts
andsrc/frontend/KindeBrowserClient.js
usepermissions: []
- Return types in getPermissions methods correctly handle the
KindePermissions | []
type🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for permission type definitions and usages echo "Checking permission type definitions:" ast-grep --pattern 'type $_ = { $$$ permissions: $_ $$$ }' echo -e "\nChecking permission property access patterns:" rg -A 2 'permissions:' --type typescriptLength of output: 403
Script:
#!/bin/bash # Search for permission type definitions and usages with ripgrep echo "Checking permission type definitions:" rg "type.*\{.*permissions.*\}" -A 3 echo -e "\nChecking permission property access and usage:" rg "permissions(\s*):(\s*)" -A 2 echo -e "\nChecking permission type imports:" rg "import.*Permission" -A 1Length of output: 2560
types.d.ts (1)
306-306
: Verify the impact of permission type changes across the codebase.Let's ensure these type changes don't break existing permission checks in the codebase.
Also applies to: 340-340
✅ Verification successful
Type change appears safe and properly handled across the codebase
The verification shows that the
KindePermissions
type is used consistently and safely:
- Type is only defined in
types.d.ts
and referenced in key authentication files- Permission checks in
protect.js
properly handle both array cases- Frontend components in
KindeBrowserClient.js
andAuthProvider.jsx
safely access permissions through optional chaining🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for permission-related type usage patterns echo "Checking permission type usage patterns..." rg -l "KindePermissions" --type typescript echo "\nChecking permission access patterns..." rg "getPermissions\(\)" --type typescript -B 2 -A 2 echo "\nChecking direct permission property access..." rg "\.permissions\." --type typescript -B 2 -A 2Length of output: 543
Script:
#!/bin/bash # Search for permission-related type usage patterns without file type filter echo "Checking permission type usage patterns..." rg -l "KindePermissions" echo "\nChecking permission access patterns..." rg "getPermissions\(\)" -B 2 -A 2 echo "\nChecking direct permission property access..." rg "\.permissions\." -B 2 -A 2 # Also check for any TypeScript/JavaScript files that might use these patterns echo "\nListing relevant files..." fd "\.(ts|tsx|js|jsx|d\.ts)$"Length of output: 4699
types.d.ts
Outdated
@@ -303,7 +303,7 @@ export type KindeState = { | |||
isAuthenticated: boolean | null; | |||
isLoading: boolean | null; | |||
organization: KindeOrganization; | |||
permissions: KindePermissions; | |||
permissions: KindePermissions | []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more specific union type for permissions.
The current type KindePermissions | []
could lead to runtime errors when code expects the permissions
and orgCode
properties. Consider using a more type-safe alternative:
- permissions: KindePermissions | [];
+ permissions: KindePermissions | { permissions: []; orgCode: null };
This ensures that even when empty, the permissions object maintains a consistent structure, preventing potential runtime errors.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
permissions: KindePermissions | []; | |
permissions: KindePermissions | { permissions: []; orgCode: null }; |
types.d.ts
Outdated
@@ -337,7 +337,7 @@ export type KindeState = { | |||
getPermission: ( | |||
key: string | |||
) => {isGranted: boolean; orgCode: string | null} | null; | |||
getPermissions: () => KindePermissions; | |||
getPermissions: () => KindePermissions | []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure consistent typing between permissions property and getPermissions method.
The return type of getPermissions
should match the type of the permissions
property. If we update the property type as suggested above, we should also update this method:
- getPermissions: () => KindePermissions | [];
+ getPermissions: () => KindePermissions | { permissions: []; orgCode: null };
This maintains type consistency and prevents potential type mismatches between the property and its getter method.
Committable suggestion was skipped due to low confidence.
Explain your changes
getUserOrganizations()
#211Checklist
🛟 If you need help, consider asking for advice over in the Kinde community.