Skip to content

fix(claim-db-worker): make claim page SSR-safe and restore integration-token project check#81

Merged
aidankmcalister merged 1 commit intomainfrom
fix/fix-claim-flow-ssr-and-project-check
Mar 4, 2026
Merged

fix(claim-db-worker): make claim page SSR-safe and restore integration-token project check#81
aidankmcalister merged 1 commit intomainfrom
fix/fix-claim-flow-ssr-and-project-check

Conversation

@aidankmcalister
Copy link
Member

@aidankmcalister aidankmcalister commented Mar 3, 2026

  • Fixes window is not defined on /claim by removing window usage during render and only building callback URL inside the click handler.
  • Restores project pre-check to use INTEGRATION_TOKEN (owner token), which prevents false 404 resource-not-found before transfer.
  • Updates tests for usePathname mocking and current PostHog proxy host expectation.
  • Verification: pnpm test in claim-db-worker passes (11/11).

Summary by CodeRabbit

  • Tests

    • Updated test expectations for URL verification and pathname mocking
  • Refactor

    • Enhanced redirect and validation handling in the claim flow

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

Walkthrough

This 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

Cohort / File(s) Summary
Test Updates
claim-db-worker/__tests__/callback-api.test.ts, claim-db-worker/__tests__/claim.test.tsx
Updated fetch URL test expectation from posthog.com to proxyhog.prisma-data.net; added usePathname import and mock with return value "/claim".
App Logic
claim-db-worker/app/claim/page.tsx
Added pathname-based redirect logic using usePathname and useEffect. Introduced runtime validation throwing error if projectID missing. Moved redirectUri construction inside claim handler instead of pre-constructing it. Updated early return condition to use pathname checks.
Code Formatting
claim-db-worker/lib/auth-utils.ts
Reformatted validateProject function signature by moving parameter list to separate line; no behavioral changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(claim-db-worker): make claim page SSR-safe and restore integration-token project check' directly and accurately summarizes the main changes: making the claim page SSR-safe (removing window usage) and restoring the integration-token project check, which aligns with the actual modifications across all affected files.

✏️ 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).
Share your feedback on Discord.


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

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

Preview CLIs & Workers are live!

Test the CLIs locally under tag pr81-fix-fix-claim-flow-ssr-and-project-check-22630737369:

npx create-db@pr81
npx create-pg@pr81
npx create-postgres@pr81

Worker URLs
• Create-DB Worker: https://create-db-temp.prisma.io
• Claim-DB Worker: https://create-db.prisma.io

These will live as long as this PR exists under tag pr81-fix-fix-claim-flow-ssr-and-project-check-22630737369.

@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

Copy link

@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 (2)
claim-db-worker/__tests__/claim.test.tsx (1)

37-37: Add branch coverage for the new pathname guard.

Right now usePathname is always "/claim". Please add tests for:

  • missing projectID on non-test path (expects redirect),
  • missing projectID on "/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 single isTestPath guard and router.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

📥 Commits

Reviewing files that changed from the base of the PR and between 39b32da and 4563b4e.

📒 Files selected for processing (4)
  • claim-db-worker/__tests__/callback-api.test.ts
  • claim-db-worker/__tests__/claim.test.tsx
  • claim-db-worker/app/claim/page.tsx
  • claim-db-worker/lib/auth-utils.ts

@aidankmcalister aidankmcalister merged commit d6e3c1b into main Mar 4, 2026
6 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