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.

feat(agentic): add account-mismatch page for provisioning partners (#58880)

Matt Brookerdfe52c8418dc
diff --git a/ee/api/agentic_provisioning/test/test_authorize.py b/ee/api/agentic_provisioning/test/test_authorize.py
index 7bb34c987c70..4eb05e0b03c8 100644
--- a/ee/api/agentic_provisioning/test/test_authorize.py
+++ b/ee/api/agentic_provisioning/test/test_authorize.py
@@ -1,5 +1,6 @@
import json
import time
+from urllib.parse import quote
import pytest
from posthog.test.base import APIBaseTest
@@ -45,11 +46,15 @@ class TestAgenticAuthorize(APIBaseTest):
assert res.status_code == 302
assert "error=missing_state" in res["Location"]
- def test_email_mismatch_redirects_with_error(self):
- self._set_pending_auth("state_mismatch", "[email protected]")
+ def test_email_mismatch_redirects_to_mismatch_page(self):
+ self._set_pending_auth("state_mismatch", "[email protected]", partner_name="Test Partner")
res = self.client.get("/api/agentic/authorize?state=state_mismatch")
assert res.status_code == 302
- assert "error=email_mismatch" in res["Location"]
+ assert "/agentic/account-mismatch" in res["Location"]
+ assert "expected_email=other%40example.com" in res["Location"]
+ assert f"current_email={quote(self.user.email)}" in res["Location"]
+ assert "partner_name=Test+Partner" in res["Location"]
+ assert "state=state_mismatch" in res["Location"]
def test_redirects_to_callback_with_code(self):
self._set_pending_auth("state_ok", self.user.email)
diff --git a/ee/api/agentic_provisioning/views.py b/ee/api/agentic_provisioning/views.py
index a4f86b5d431d..e80fbf27e083 100644
--- a/ee/api/agentic_provisioning/views.py
+++ b/ee/api/agentic_provisioning/views.py
@@ -710,7 +710,15 @@ def agentic_authorize(request: Any) -> HttpResponseBase:
if request.user.email != pending["email"]:
_capture_provisioning_event("authorize", "email_mismatch")
- return HttpResponseRedirect(f"{settings.SITE_URL}?error=email_mismatch")
+ mismatch_params = urlencode(
+ {
+ "expected_email": pending["email"],
+ "current_email": request.user.email,
+ "partner_name": pending.get("partner_name", ""),
+ "state": state,
+ }
+ )
+ return HttpResponseRedirect(f"{settings.SITE_URL.rstrip('/')}/agentic/account-mismatch?{mismatch_params}")
user = request.user
memberships = list(user.organization_memberships.select_related("organization").all())
diff --git a/frontend/src/scenes/appScenes.ts b/frontend/src/scenes/appScenes.ts
index 1cde5a02216e..4eeba3dd5ccd 100644
--- a/frontend/src/scenes/appScenes.ts
+++ b/frontend/src/scenes/appScenes.ts
@@ -128,6 +128,7 @@ export const appScenes: Record<Scene | string, () => any> = {
[Scene.Unsubscribe]: () => import('./Unsubscribe/Unsubscribe'),
[Scene.VercelConnect]: () => import('./authentication/VercelConnect'),
[Scene.VercelLinkError]: () => import('./authentication/VercelLinkError'),
+ [Scene.AgenticAccountMismatch]: () => import('./authentication/AgenticAccountMismatch'),
[Scene.VerifyEmail]: () => import('./authentication/signup/verify-email/VerifyEmail'),
[Scene.WebAnalyticsWebVitals]: () => import('./web-analytics/WebAnalyticsScene'),
[Scene.WebAnalyticsHealth]: () => import('./web-analytics/WebAnalyticsScene'),
diff --git a/frontend/src/scenes/authentication/AgenticAccountMismatch.tsx b/frontend/src/scenes/authentication/AgenticAccountMismatch.tsx
new file mode 100644
index 000000000000..5e8f4e4f5a15
--- /dev/null
+++ b/frontend/src/scenes/authentication/AgenticAccountMismatch.tsx
@@ -0,0 +1,75 @@
+import { useValues } from 'kea'
+import { router } from 'kea-router'
+
+import { LemonButton } from '@posthog/lemon-ui'
+
+import { getCookie } from 'lib/api'
+import { BridgePage } from 'lib/components/BridgePage/BridgePage'
+import { IconErrorOutline } from 'lib/lemon-ui/icons'
+import { SceneExport } from 'scenes/sceneTypes'
+
+export const scene: SceneExport = {
+ component: AgenticAccountMismatch,
+}
+
+export function AgenticAccountMismatch(): JSX.Element {
+ const { searchParams } = useValues(router)
+
+ const expectedEmail = typeof searchParams.expected_email === 'string' ? searchParams.expected_email : ''
+ const currentEmail =
+ typeof searchParams.current_email === 'string' ? searchParams.current_email : 'your current account'
+ const partnerName = typeof searchParams.partner_name === 'string' ? searchParams.partner_name : 'the requesting app'
+ const state = typeof searchParams.state === 'string' ? searchParams.state : ''
+
+ const nextUrl = state ? `/api/agentic/authorize?state=${encodeURIComponent(state)}` : null
+
+ const submitLogout = (): void => {
+ const form = document.createElement('form')
+ form.method = 'POST'
+ form.action = '/logout'
+ form.style.display = 'none'
+
+ const csrfInput = document.createElement('input')
+ csrfInput.type = 'hidden'
+ csrfInput.name = 'csrfmiddlewaretoken'
+ csrfInput.value = getCookie('posthog_csrftoken') || ''
+ form.appendChild(csrfInput)
+
+ if (nextUrl) {
+ const nextInput = document.createElement('input')
+ nextInput.type = 'hidden'
+ nextInput.name = 'next'
+ nextInput.value = nextUrl
+ form.appendChild(nextInput)
+ }
+
+ document.body.appendChild(form)
+ form.submit()
+ }
+
+ return (
+ <BridgePage view="agentic-account-mismatch">
+ <div className="text-center mb-4">
+ <IconErrorOutline className="text-warning text-4xl" />
+ </div>
+ <h2 className="text-center">Account mismatch</h2>
+ <div className="text-center mb-6">
+ <p className="mb-2">
+ You're currently logged in as <strong>{currentEmail}</strong>, but your {partnerName} account is
+ linked to {expectedEmail ? <strong>{expectedEmail}</strong> : 'a different PostHog account'}.
+ </p>
+ <p>To continue, log out and sign in with the correct email.</p>
+ </div>
+ <div className="flex flex-col gap-2">
+ <LemonButton fullWidth type="primary" center onClick={submitLogout}>
+ {expectedEmail ? `Log out and continue as ${expectedEmail}` : 'Log out and continue'}
+ </LemonButton>
+ <LemonButton fullWidth type="secondary" center to="/">
+ Cancel
+ </LemonButton>
+ </div>
+ </BridgePage>
+ )
+}
+
+export default AgenticAccountMismatch
diff --git a/frontend/src/scenes/sceneLogic.tsx b/frontend/src/scenes/sceneLogic.tsx
index 1201e6a308a1..5a91c7622bf3 100644
--- a/frontend/src/scenes/sceneLogic.tsx
+++ b/frontend/src/scenes/sceneLogic.tsx
@@ -310,8 +310,8 @@ const pathPrefixesOnboardingNotRequiredFor = [
'/oauth',
// /connect/vercel/link (urls.vercelConnect) and other connect round-trips.
'/connect',
- // /agentic/authorize.
- '/agentic/authorize',
+ // /agentic/authorize, /agentic/account-mismatch.
+ '/agentic',
// /cli/authorize, /cli/live (CLI auth round-trip).
'/cli',
'/startups',
diff --git a/frontend/src/scenes/sceneTypes.ts b/frontend/src/scenes/sceneTypes.ts
index 5bf6941252b0..650a82b31365 100644
--- a/frontend/src/scenes/sceneTypes.ts
+++ b/frontend/src/scenes/sceneTypes.ts
@@ -10,6 +10,7 @@ export enum Scene {
Action = 'Action',
Actions = 'Actions',
AdvancedActivityLogs = 'AdvancedActivityLogs',
+ AgenticAccountMismatch = 'AgenticAccountMismatch',
AgenticAuthorize = 'AgenticAuthorize',
Annotations = 'Annotations',
Approval = 'Approval',
diff --git a/frontend/src/scenes/scenes.ts b/frontend/src/scenes/scenes.ts
index 52230852b960..94b8d737f982 100644
--- a/frontend/src/scenes/scenes.ts
+++ b/frontend/src/scenes/scenes.ts
@@ -346,6 +346,7 @@ export const sceneConfigurations: Record<Scene | string, SceneConfig> = {
[Scene.TwoFactorReset]: { allowUnauthenticated: true, layout: 'plain' },
[Scene.VercelConnect]: { allowUnauthenticated: true, layout: 'plain', name: 'Connect to Vercel' },
[Scene.VercelLinkError]: { layout: 'plain', name: 'Vercel account mismatch' },
+ [Scene.AgenticAccountMismatch]: { layout: 'plain', name: 'Account mismatch', allowUnauthenticated: true },
[Scene.Person]: {
projectBased: true,
name: 'People',
@@ -875,6 +876,7 @@ export const routes: Record<string, [Scene | string, string]> = {
[urls.verifyEmail(':uuid', ':token')]: [Scene.VerifyEmail, 'verifyEmailWithToken'],
[urls.vercelConnect()]: [Scene.VercelConnect, 'vercelConnect'],
[urls.vercelLinkError()]: [Scene.VercelLinkError, 'vercelLinkError'],
+ [urls.agenticAccountMismatch()]: [Scene.AgenticAccountMismatch, 'agenticAccountMismatch'],
[urls.unsubscribe()]: [Scene.Unsubscribe, 'unsubscribe'],
[urls.integrationsRedirect(':kind')]: [Scene.IntegrationsRedirect, 'integrationsRedirect'],
[urls.stripeConfirmInstall()]: [Scene.StripeConfirmInstall, 'stripeConfirmInstall'],
diff --git a/frontend/src/scenes/urls.ts b/frontend/src/scenes/urls.ts
index 0c63edfff2f9..d6e56acc5b6d 100644
--- a/frontend/src/scenes/urls.ts
+++ b/frontend/src/scenes/urls.ts
@@ -165,6 +165,7 @@ export const urls = {
`/verify_email${userUuid ? `/${userUuid}` : ''}${token ? `/${token}` : ''}`,
vercelConnect: (): string => '/connect/vercel/link',
vercelLinkError: (): string => '/integrations/vercel/link-error',
+ agenticAccountMismatch: (): string => '/agentic/account-mismatch',
inviteSignup: (id: string): string => `/signup/${id}`,
onboarding: ({
campaign,
diff --git a/posthog/urls.py b/posthog/urls.py
index 84f3d2f52f84..e9d10b470c5c 100644
--- a/posthog/urls.py
+++ b/posthog/urls.py
@@ -480,6 +480,7 @@ frontend_unauthenticated_routes = [
"login",
"unsubscribe",
"verify_email",
+ r"agentic/account-mismatch",
]
for route in frontend_unauthenticated_routes:
urlpatterns.append(re_path(route, home))