fix(claim-db-worker): make claim page SSR-safe and restore integration-token project check#81
Conversation
…n-token project check
WalkthroughThis PR updates test expectations for URL verification, adds usePathname mock to tests, introduces pathname-based redirect logic in the claim page using useEffect with projectID runtime validation, and reformats an auth-utils function signature. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Comment |
|
✅ Preview CLIs & Workers are live! Test the CLIs locally under tag npx create-db@pr81
npx create-pg@pr81
npx create-postgres@pr81Worker URLs
|
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
claim-db-worker | 4563b4e | Commit Preview URL Branch Preview URL |
Mar 03 2026, 03:46 PM |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
claim-db-worker/__tests__/claim.test.tsx (1)
37-37: Add branch coverage for the new pathname guard.Right now
usePathnameis always"/claim". Please add tests for:
- missing
projectIDon non-test path (expects redirect),- missing
projectIDon"/test/"path (expects no redirect).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@claim-db-worker/__tests__/claim.test.tsx` at line 37, Add two tests in claim.test.tsx that exercise the pathname guard by mocking usePathname and projectID: (1) mock vi.mocked(usePathname).mockReturnValue("/claim") (or any non-test path) and ensure projectID is undefined/absent and assert the component triggers a redirect as expected; (2) mock vi.mocked(usePathname).mockReturnValue("/test/whatever") with projectID undefined and assert no redirect occurs. Use the same render/setup helpers already in the file to mount the component and assert redirect behavior (e.g., router push or returned null) so both branches of the pathname guard are covered.claim-db-worker/app/claim/page.tsx (1)
15-22: Harden pathname guard logic and avoid history pollution on redirect.
includes("/test/")is a bit brittle for route intent checks. Consider a singleisTestPathguard androuter.replace("/")for this automatic redirect.♻️ Proposed refactor
+ const isTestPath = pathname === "/test" || pathname.startsWith("/test/"); useEffect(() => { - if (!projectID && !pathname.includes("/test/")) { - router.push("/"); + if (!projectID && !isTestPath) { + router.replace("/"); } - }, [pathname, projectID, router]); + }, [isTestPath, projectID, router]); - if (!projectID && !pathname.includes("/test/")) { + if (!projectID && !isTestPath) { return null; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@claim-db-worker/app/claim/page.tsx` around lines 15 - 22, Replace the brittle inline pathname checks with a single guard (e.g., isTestPath) and use router.replace("/") to avoid polluting history: create an isTestPath helper that encapsulates the intent (for example using startsWith or a stricter regex instead of includes), use that helper in both the useEffect block (where you currently call router.push) and the render-time guard that returns null when projectID is missing; change router.push to router.replace in the effect so the redirect doesn't add a history entry and ensure both places reference the same isTestPath logic (symbols: useEffect, pathname, projectID, router, isTestPath, router.replace).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@claim-db-worker/__tests__/claim.test.tsx`:
- Line 37: Add two tests in claim.test.tsx that exercise the pathname guard by
mocking usePathname and projectID: (1) mock
vi.mocked(usePathname).mockReturnValue("/claim") (or any non-test path) and
ensure projectID is undefined/absent and assert the component triggers a
redirect as expected; (2) mock
vi.mocked(usePathname).mockReturnValue("/test/whatever") with projectID
undefined and assert no redirect occurs. Use the same render/setup helpers
already in the file to mount the component and assert redirect behavior (e.g.,
router push or returned null) so both branches of the pathname guard are
covered.
In `@claim-db-worker/app/claim/page.tsx`:
- Around line 15-22: Replace the brittle inline pathname checks with a single
guard (e.g., isTestPath) and use router.replace("/") to avoid polluting history:
create an isTestPath helper that encapsulates the intent (for example using
startsWith or a stricter regex instead of includes), use that helper in both the
useEffect block (where you currently call router.push) and the render-time guard
that returns null when projectID is missing; change router.push to
router.replace in the effect so the redirect doesn't add a history entry and
ensure both places reference the same isTestPath logic (symbols: useEffect,
pathname, projectID, router, isTestPath, router.replace).
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
claim-db-worker/__tests__/callback-api.test.tsclaim-db-worker/__tests__/claim.test.tsxclaim-db-worker/app/claim/page.tsxclaim-db-worker/lib/auth-utils.ts
window is not definedon/claimby removingwindowusage during render and only building callback URL inside the click handler.INTEGRATION_TOKEN(owner token), which prevents false404 resource-not-foundbefore transfer.usePathnamemocking and current PostHog proxy host expectation.pnpm testinclaim-db-workerpasses (11/11).Summary by CodeRabbit
Tests
Refactor