Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

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

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Dec 14, 2025

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

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 14, 2025

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
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Additional Comments (1)

  1. apps/sim/lib/auth/auth-client.ts, line 45 (link)

    logic: useActiveOrganization exported here will be undefined when billing is disabled (since organizationClient() won't be included in plugins). Accessing client.useActiveOrganization in team-usage.tsx:19 may cause runtime errors.

    Consider adding a conditional export or wrapping usage in checks:

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit d5b95cb into staging Dec 14, 2025
10 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/404 branch December 14, 2025 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants