sim icon indicating copy to clipboard operation
sim copied to clipboard

fix(organizations): move organization better-auth client to conditionally be included based on FF

Open waleedlatif1 opened this issue 2 months ago • 2 comments

Summary

  • move organization better-auth client to conditionally be included based on FF
  • since we have it conditionally included on the server auth.ts and 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)

waleedlatif1 avatar Dec 14 '25 01:12 waleedlatif1

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Dec 14, 2025 2:51am

vercel[bot] avatar Dec 14 '25 01:12 vercel[bot]

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 the isBillingEnabled conditional block alongside stripeClient()
  • Added conditional wrapper for useActiveOrganization that 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 useActiveOrganization stub 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-apps[bot] avatar Dec 14 '25 01:12 greptile-apps[bot]

@greptile

waleedlatif1 avatar Dec 14 '25 02:12 waleedlatif1