sim
sim copied to clipboard
fix(organizations): move organization better-auth client to conditionally be included based on FF
Summary
- move organization better-auth client to conditionally be included based on FF
- since we have it conditionally included on the server
auth.tsand enabled all the time on the client, it always checked for an org and got a 404 back every time, but now they are aligned
Type of Change
- [x] Bug fix
Testing
Tested manually
Checklist
- [x] Code follows project style guidelines
- [x] Self-reviewed my changes
- [x] Tests added/updated and passing
- [x] No new warnings introduced
- [x] I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
The latest updates on your projects. Learn more about Vercel for GitHub.
Greptile Overview
Greptile Summary
Fixed client-server misalignment where organizationClient() was unconditionally enabled on the client but conditionally enabled on the server based on the isBillingEnabled feature flag, causing 404 errors on every request when billing was disabled.
Changes:
- Moved
organizationClient()inside theisBillingEnabledconditional block alongsidestripeClient() - Added conditional wrapper for
useActiveOrganizationthat returns a stub function ({ data: undefined, isPending: false, error: null }) when billing is disabled
Impact:
- Eliminates 404 errors in self-hosted instances with billing disabled
- Maintains backward compatibility for code using
useActiveOrganization(apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/team-management/components/team-usage/team-usage.tsx) - Aligns client and server plugin configuration
Confidence Score: 5/5
- This PR is safe to merge with no risk
- The changes are minimal, focused, and correctly implement feature flag alignment. The solution properly mirrors the server-side conditional logic (auth.ts:1966-2183) on the client side, and the
useActiveOrganizationstub function signature matches what consuming code expects based on usage patterns - No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/lib/auth/auth-client.ts | 5/5 | Aligned organizationClient() and useActiveOrganization with isBillingEnabled feature flag to prevent 404 errors when billing is disabled |
Sequence Diagram
sequenceDiagram
participant Client as Auth Client
participant FF as Feature Flag (isBillingEnabled)
participant Server as Auth Server
participant OrgPlugin as Organization Plugin
Note over Client,OrgPlugin: Before PR (Misaligned)
Client->>Client: Always includes organizationClient()
Client->>Server: Request organization data
Server->>FF: Check isBillingEnabled
alt Billing Disabled
Server-->>Client: 404 Not Found
Note over Client: organizationClient() enabled<br/>but server plugin disabled
end
Note over Client,OrgPlugin: After PR (Aligned)
Client->>FF: Check isBillingEnabled
alt Billing Enabled
Client->>Client: Include organizationClient()
Client->>Server: Request organization data
Server->>OrgPlugin: Process request
OrgPlugin-->>Server: Return organization
Server-->>Client: Success
else Billing Disabled
Client->>Client: Exclude organizationClient()
Client->>Client: useActiveOrganization returns stub
Note over Client: No server request,<br/>no 404 error
end
@greptile