Skip to content

Conversation

@sweetmantech
Copy link
Collaborator

@sweetmantech sweetmantech commented Feb 10, 2026

Summary

  • Added Authorization: Bearer header using Privy access token to authenticate with the API (which now requires auth)
  • Fixed query parameter from accountId (camelCase) to account_id (snake_case) to match the updated API spec

Root cause: The API's /api/organizations endpoint was updated to require authentication and uses account_id as the query param name. Without these changes, the endpoint returned empty/unauthorized results, causing the org list to show only a personal account.

Test plan

  • Log in and verify the org selector dropdown shows all organizations
  • Verify switching between orgs still works correctly
  • Verify creating a new org still works and appears in the list

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Organizations data now requires a valid authenticated session before loading, preventing unauthorized access.
    • Organizations list will only fetch when the user is signed in and account information is available.
  • Documentation

    • Updated notes to reflect that the backend resolves the account from authentication and no extra query parameters are needed.

The API now requires authentication and uses snake_case query params.
Added Bearer token auth via Privy and changed accountId to account_id.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@vercel
Copy link
Contributor

vercel bot commented Feb 10, 2026

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

Project Deployment Actions Updated (UTC)
recoup-chat Ready Ready Preview Feb 11, 2026 6:02am

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

fetchAccountOrganizations was changed to accept an access token and call /api/organizations with an Authorization: Bearer <token> header; useAccountOrganizations now obtains the access token via useAccessToken and enables the query only when both userData.account_id and a valid access token are present.

Changes

Cohort / File(s) Summary
Account organizations hook
hooks/useAccountOrganizations.ts
Reworked fetchAccountOrganizations signature to fetchAccountOrganizations(accessToken: string). Query now calls /api/organizations with Authorization: Bearer <token> and no accountId query param. useAccountOrganizations retrieves token via useAccessToken, passes it to fetchAccountOrganizations, and enables the query only when userData.account_id and the access token exist. Updated docs/comment and imports accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Hook as useAccountOrganizations
    participant Auth as useAccessToken
    participant Fetch as fetchAccountOrganizations
    participant API as /api/organizations (Server)

    Hook->>Auth: request access token
    Auth-->>Hook: returns accessToken
    Hook->>Fetch: call fetchAccountOrganizations(accessToken)
    Fetch->>API: GET /api/organizations\nHeaders: Authorization: Bearer <accessToken>
    API-->>Fetch: 200 OK (organizations)
    Fetch-->>Hook: returns organizations
Loading

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Token clasped, the call sets sail,
Bearer whisper tells the tale,
Accounts resolved on server shore,
Hooks fetch home, and ask no more. ✨

🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Solid & Clean Code ✅ Passed Code demonstrates solid adherence to SOLID principles and clean code practices with focused single-purpose functions, proper composition through established hooks, DRY through centralized constants, straightforward KISS logic, and clean practices including descriptive naming, proper error handling, and TypeScript type safety.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sweetmantech/myc-4210-chat-get-apiorganizations-fix-for-new-api-changes

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d549dafa3b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 49 to 50
if (!accessToken) {
throw new Error("Not authenticated");

Choose a reason for hiding this comment

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

P2 Badge Gate org query on Privy auth before throwing

This query is enabled as soon as userData?.account_id exists, but it now hard-fails when getAccessToken() returns null. During startup, account_id can be present before Privy has finished token initialization, so the query enters an error state ("Not authenticated") even though the user is signed in; with refetchOnWindowFocus: false, that can leave the org list stuck until a manual refresh/invalidation. Include Privy auth readiness in enabled (or avoid throwing for the transient no-token case) so initial load can recover automatically.

Useful? React with 👍 / 👎.

Bearer tokens resolve to orgId=null (personal key behavior), so passing
account_id as a query param causes the API to reject with 400/403.
The API resolves the account from the Bearer token directly — no query
params needed. Also switched to the useAccessToken hook to match the
established pattern used by useConnectors.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@sweetmantech sweetmantech merged commit ef2a128 into test Feb 11, 2026
2 checks passed
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.

1 participant