Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/upset-sides-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Invalidate organization memberships based on client user
1 change: 1 addition & 0 deletions packages/shared/src/react/hooks/useOrganizationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export function useOrganizationList<T extends UseOrganizationListParams>(params?
{
type: 'userMemberships',
userId: user?.id,
memberships: user?.organizationMemberships.length ?? 0,
},
Comment on lines 324 to 327
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Potential runtime crash: optional chain organizationMemberships before accessing .length

If user is defined but organizationMemberships is undefined/null (e.g., not expanded/initialized yet), user?.organizationMemberships.length will throw. Chain through organizationMemberships as well.

Apply this diff:

       type: 'userMemberships',
       userId: user?.id,
-      memberships: user?.organizationMemberships.length ?? 0,
+      memberships: user?.organizationMemberships?.length ?? 0,
📝 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.

Suggested change
type: 'userMemberships',
userId: user?.id,
memberships: user?.organizationMemberships.length ?? 0,
},
type: 'userMemberships',
userId: user?.id,
- memberships: user?.organizationMemberships.length ?? 0,
+ memberships: user?.organizationMemberships?.length ?? 0,
},
🤖 Prompt for AI Agents
In packages/shared/src/react/hooks/useOrganizationList.tsx around lines 324 to
327, the optional chain stops at user so accessing
user?.organizationMemberships.length can throw if organizationMemberships is
undefined; update the expression to safely chain through organizationMemberships
(e.g., use user?.organizationMemberships?.length ?? 0) so memberships falls back
to 0 when organizationMemberships is undefined or null.

);

Expand Down
Loading