fix(billing): correct URL construction and prevent double-redirecting#2034
Merged
jonathanlab merged 2 commits intomainfrom May 5, 2026
Merged
Conversation
Generated-By: PostHog Code Task-Id: 156e6cbd-e2c4-4d62-bd3d-969dc2b57010
Contributor
Prompt To Fix All With AIFix the following 3 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 3
apps/code/src/renderer/utils/urls.test.ts:14-24
The region-specific test cases for both `getPostHogUrl` and `getBillingUrl` are repetitive and should be expressed as parameterised tests — the team's stated preference. Duplicate test bodies hide whether the assertion is actually exercising distinct behaviour or just paraphrasing the same check with different literals.
```suggestion
it.each([
["us", "/foo", "https://us.posthog.com/foo"],
["us", "foo", "https://us.posthog.com/foo"],
["eu", "/foo", "https://eu.posthog.com/foo"],
])("joins base and path for %s region (path=%s)", (region, path, expected) => {
expect(getPostHogUrl(path, region as "us" | "eu")).toBe(expected);
});
```
### Issue 2 of 3
apps/code/src/renderer/utils/urls.test.ts:28-38
Same parameterisation opportunity for the `getBillingUrl` region cases — the two "points at" tests differ only in region and expected host, making `it.each` the right tool.
```suggestion
it.each([
["us", "https://us.posthog.com/organization/billing/overview"],
["eu", "https://eu.posthog.com/organization/billing/overview"],
])("points at /organization/billing/overview on %s", (region, expected) => {
expect(getBillingUrl(region as "us" | "eu")).toBe(expected);
});
```
### Issue 3 of 3
apps/code/src/renderer/features/settings/components/sections/PlanUsageSettings.tsx:71
**`redirectUrl` value is silently discarded**
The old code passed `redirectUrl` to `getPostHogUrl()` as the path — that was broken when the backend returned a full URL. The new code fixes the double-scheme issue, but now completely ignores the backend-supplied URL: `redirectUrl` only controls whether the callout is shown; its actual value is thrown away. If the backend ever sends a redirect to a specific checkout or payment-setup page (rather than the generic billing overview), users will silently land on the wrong page.
```suggestion
const redirectFullUrl = redirectUrl ? billingUrl : null;
```
Reviews (1): Last reviewed commit: "fix: correct billing URL construction an..." | Re-trigger Greptile |
k11kirky
approved these changes
May 5, 2026
Address Greptile feedback on PR #2034: - getPostHogUrl now passes absolute URLs through unchanged, so a backend-supplied redirect_url is no longer flattened into the generic billing overview when it points at a specific checkout/payment page. - PlanUsageSettings runs redirectUrl through getPostHogUrl again and falls back to the static billing URL only when the value can't be resolved. - Tests for region variants are parameterized with it.each, plus new coverage for absolute-URL passthrough. Generated-By: PostHog Code Task-Id: 156e6cbd-e2c4-4d62-bd3d-969dc2b57010
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Fixes a critical billing navigation bug where the billing link was constructing malformed URLs with double schemes (e.g.,
https://us.posthog.com/project/219767/https://app.posthog.com/organization/billing), resulting in 404 errors. Introduces a dedicatedgetBillingUrl()function to ensure consistent, correct billing URL construction across the application.What changed?
getBillingUrl()function inurls.tsthat constructs the correct billing URL (/organization/billing/overview) with proper region handlingPlanUsageSettings.tsx:getPostHogUrl("/organization/billing")withgetBillingUrl()urls.test.tsto prevent regression:getPostHogUrl()behavior with different regionsgetBillingUrl()returning correct URLs for US and EU regionsHow did you test this?
The changes include new unit tests in
urls.test.tsthat verify:/project/paths in billing URLsCreated with PostHog Code