Skip to content

detect signedin->guest transition for usage#2017

Open
ignaciojimenezr wants to merge 1 commit intomainfrom
sidebar-auth-check
Open

detect signedin->guest transition for usage#2017
ignaciojimenezr wants to merge 1 commit intomainfrom
sidebar-auth-check

Conversation

@ignaciojimenezr
Copy link
Copy Markdown
Collaborator

@ignaciojimenezr ignaciojimenezr commented May 5, 2026

  • Fixes the sign-out white flash by preventing billing:getCreditBalance from throwing during transient auth states.
  • Returns null from the credit balance query when identity/user rows are missing, while keeping mutation auth strict.
  • Adds guest-aware credit balance support so guest usage still works.
  • Adds useActor() to gate frontend queries on confirmed loading, user, or guest state.
  • Wraps sidebar credit usage in a production-safe error boundary with dev logging enabled.
  • Adds focused backend and frontend tests for missing auth, missing user rows, guest balance, and actor/query gating.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 5, 2026
@chelojimenez
Copy link
Copy Markdown
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

Walkthrough

This pull request introduces a new useActor hook that consolidates authentication state by combining WorkOS and Convex authentication signals with a user-row query. The useCreditBalance hook is refactored to depend on useActor instead of directly accessing Convex auth. A new SafeSidebarCreditUsage wrapper component is added, rendering the credit usage component inside an ErrorBoundary with conditional error logging in development mode. Sidebar components are updated to render the safe variant. The ErrorBoundary component gains an optional logErrors prop to suppress console error output. Comprehensive test coverage is added for both new hooks, covering loading, authenticated, and guest states.


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
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
mcpjam-inspector/client/src/hooks/__tests__/useActor.test.tsx (1)

60-71: ⚡ Quick win

Add one explicit cross-auth mismatch test (WorkOS user present, Convex identity absent).

That case is central to transition safety and currently implicit; pinning it would prevent subtle regressions in status resolution.

Proposed test addition
+  it("does not report user when WorkOS has a user but Convex has no identity", () => {
+    mockUseAuth.mockReturnValue({
+      user: { id: "workos_user_123" },
+      isLoading: false,
+    });
+    mockUseConvexAuth.mockReturnValue({
+      isAuthenticated: false,
+      isLoading: false,
+    });
+
+    const { result } = renderHook(() => useActor());
+
+    expect(result.current.status).toBe("guest");
+    expect(result.current.isAuthenticated).toBe(false);
+    expect(mockUseQuery).toHaveBeenCalledWith("users:getCurrentUser", "skip");
+  });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@mcpjam-inspector/client/src/hooks/__tests__/useActor.test.tsx` around lines
60 - 71, Add a test that explicitly covers the cross-auth mismatch:
mockUseConvexAuth should return isAuthenticated: false/isLoading: false while
mockUseQuery returns a WorkOS user object when the WorkOS query key used by
useActor is invoked; renderHook(() => useActor()) and assert that result.current
reflects the WorkOS-authenticated state (i.e., status is the WorkOS/user status
used in your hook and result.current.isAuthenticated reflects the WorkOS
presence), and also assert mockUseQuery was called for the WorkOS query key (and
that the Convex users:getCurrentUser call was not treated as the active
identity). Use the same helpers in the file (mockUseConvexAuth, mockUseQuery,
useActor) to locate where to add the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@mcpjam-inspector/client/src/hooks/__tests__/useActor.test.tsx`:
- Around line 60-71: Add a test that explicitly covers the cross-auth mismatch:
mockUseConvexAuth should return isAuthenticated: false/isLoading: false while
mockUseQuery returns a WorkOS user object when the WorkOS query key used by
useActor is invoked; renderHook(() => useActor()) and assert that result.current
reflects the WorkOS-authenticated state (i.e., status is the WorkOS/user status
used in your hook and result.current.isAuthenticated reflects the WorkOS
presence), and also assert mockUseQuery was called for the WorkOS query key (and
that the Convex users:getCurrentUser call was not treated as the active
identity). Use the same helpers in the file (mockUseConvexAuth, mockUseQuery,
useActor) to locate where to add the test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19a6364f-e715-4151-bac2-df7120aa6dab

📥 Commits

Reviewing files that changed from the base of the PR and between 7d91470 and d92c489.

📒 Files selected for processing (8)
  • mcpjam-inspector/client/src/components/mcp-sidebar.tsx
  • mcpjam-inspector/client/src/components/sidebar/sidebar-credit-usage.tsx
  • mcpjam-inspector/client/src/components/sidebar/sidebar-user.tsx
  • mcpjam-inspector/client/src/components/ui/error-boundary.tsx
  • mcpjam-inspector/client/src/hooks/__tests__/useActor.test.tsx
  • mcpjam-inspector/client/src/hooks/__tests__/useCreditBalance.test.tsx
  • mcpjam-inspector/client/src/hooks/useActor.ts
  • mcpjam-inspector/client/src/hooks/useCreditBalance.ts

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Internal preview

Preview URL: https://mcp-inspector-pr-2017.up.railway.app
Deployed commit: c7181b8
PR head commit: d92c489
Backend target: staging fallback.
Health: ❌ Convex unreachable — see job logs (staging may need convex deploy)
Access is employee-only in non-production environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants