Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(vercel): keep the popup open on new-user signup pages (#108534)

Matt Brookerd5146d10f85b
diff --git a/posthog/api/test/test_signup.py b/posthog/api/test/test_signup.py
index 1076d0298452..48bb0c1ee505 100644
--- a/posthog/api/test/test_signup.py
+++ b/posthog/api/test/test_signup.py
@@ -841,14 +841,37 @@ class TestSignupAPI(APIBaseTest):
response, "/login?error_code=no_new_organizations"
) # show the user an error; operation not permitted
+ @parameterized.expand(
+ [
+ (
+ "without_next",
+ {},
+ "/organization/confirm-creation?organization_name=HogFlix&first_name=John%20Doe&email=testemail%40posthog.com",
+ "same-origin",
+ ),
+ (
+ "with_vercel_connect_next",
+ {"next": "/connect/vercel/link?session=abc"},
+ "/organization/confirm-creation?organization_name=HogFlix&first_name=John%20Doe&email=testemail%40posthog.com&next=%2Fconnect%2Fvercel%2Flink%3Fsession%3Dabc",
+ "unsafe-none",
+ ),
+ ]
+ )
@mock.patch("social_core.backends.base.BaseAuth.request")
@pytest.mark.ee
- def test_api_social_login_to_create_organization(self, mock_request):
+ def test_api_social_login_to_create_organization(
+ self,
+ _name: str,
+ begin_params: dict[str, str],
+ expected_location: str,
+ expected_coop: str,
+ mock_request: mock.MagicMock,
+ ) -> None:
with self.settings(
SOCIAL_AUTH_GITHUB_KEY="github_123",
SOCIAL_AUTH_GITHUB_SECRET="github_secret",
):
- response = self.client.get(reverse("social:begin", kwargs={"backend": "github"}))
+ response = self.client.get(reverse("social:begin", kwargs={"backend": "github"}), begin_params)
self.assertEqual(response.status_code, status.HTTP_302_FOUND)
session = self.client.session
@@ -864,10 +887,8 @@ class TestSignupAPI(APIBaseTest):
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, status.HTTP_200_OK) # because `follow=True`
- self.assertRedirects(
- response,
- "/organization/confirm-creation?organization_name=HogFlix&first_name=John%20Doe&email=testemail%40posthog.com",
- ) # page where user will create a new org
+ self.assertRedirects(response, expected_location) # page where user will create a new org
+ self.assertEqual(response["Cross-Origin-Opener-Policy"], expected_coop)
@mock.patch("social_core.backends.base.BaseAuth.request")
@mock.patch("posthog.api.authentication.get_instance_available_sso_providers")
diff --git a/posthog/middleware.py b/posthog/middleware.py
index ca1f2fe777b5..ecff5932a21e 100644
--- a/posthog/middleware.py
+++ b/posthog/middleware.py
@@ -1254,6 +1254,16 @@ class OAuthCoopMiddleware:
"/api/agentic/oauth/",
)
+ SIGNUP_AND_LOGIN_PATHS = (
+ "/login",
+ "/login/",
+ "/signup",
+ "/signup/",
+ "/organization/confirm-creation",
+ )
+
+ SIGNUP_PATH_PREFIXES = ("/verify_email/",)
+
def __init__(self, get_response):
self.get_response = get_response
@@ -1287,7 +1297,7 @@ class OAuthCoopMiddleware:
session = getattr(request, "session", None)
session_next = session.get("next", "") if session is not None else ""
return self._targets_oauth_flow(request.GET.get("next", "")) or self._targets_oauth_flow(session_next)
- if path in ("/login", "/login/", "/signup", "/signup/"):
+ if path in self.SIGNUP_AND_LOGIN_PATHS or self._matches_oauth_prefix(path, self.SIGNUP_PATH_PREFIXES):
return self._targets_oauth_flow(request.GET.get("next", ""))
return False
diff --git a/posthog/test/test_middleware.py b/posthog/test/test_middleware.py
index 1672a33d2c62..935b81850490 100644
--- a/posthog/test/test_middleware.py
+++ b/posthog/test/test_middleware.py
@@ -2464,6 +2464,15 @@ class TestSocialAuthExceptionMiddleware(APIBaseTest):
("/signup", "next=/connect/vercel/link", None, "unsafe-none"),
("/signup", "", None, "same-origin"),
("/signup", "next=/dashboard", None, "same-origin"),
+ ("/organization/confirm-creation", "next=/connect/vercel/link?session=abc", None, "unsafe-none"),
+ ("/organization/confirm-creation", "next=/dashboard", None, "same-origin"),
+ (
+ "/verify_email/00000000-0000-0000-0000-000000000001",
+ "next=/connect/vercel/link?session=abc",
+ None,
+ "unsafe-none",
+ ),
+ ("/verify_email/00000000-0000-0000-0000-000000000001", "next=/dashboard", None, "same-origin"),
("/complete/github-link/", "", None, "same-origin"),
("/complete/slack-link/", "", None, "same-origin"),
("/login/not-a-backend/", "", None, "same-origin"),
@@ -2486,6 +2495,10 @@ class TestSocialAuthExceptionMiddleware(APIBaseTest):
"signup-next-oauth",
"signup-no-next",
"signup-next-non-oauth",
+ "confirm-creation-next-oauth",
+ "confirm-creation-next-non-oauth",
+ "verify-email-next-oauth",
+ "verify-email-next-non-oauth",
"linking-complete-github",
"linking-complete-slack",
"login-unknown-backend",