: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(auth): hint at wrong cloud region on login failure (#61962)
posthog[bot]df270f8b330b
diff --git a/frontend/src/scenes/authentication/login/loginLogic.ts b/frontend/src/scenes/authentication/login/loginLogic.tsindex c181d76e455d..23c131bdb3b1 100644--- a/frontend/src/scenes/authentication/login/loginLogic.ts+++ b/frontend/src/scenes/authentication/login/loginLogic.ts@@ -194,7 +194,7 @@ export const loginLogic = kea<loginLogicType>([},],})),- forms(({ actions, values }) => ({+ forms(({ actions }) => ({login: {defaults: { email: '', password: '' } as LoginForm,errors: ({ email, password }) => ({@@ -230,11 +230,7 @@ export const loginLogic = kea<loginLogicType>([)throw e}- let errorDetail = detail- if (code === 'invalid_credentials' && values.preflight?.cloud) {- errorDetail = detail + ' Make sure you have selected the right data region.'- }- actions.setGeneralError(code, errorDetail)+ actions.setGeneralError(code, detail)throw e}},diff --git a/frontend/src/scenes/authentication/login/variants/legacy/LegacyLogin.tsx b/frontend/src/scenes/authentication/login/variants/legacy/LegacyLogin.tsxindex c71ccde539ca..9dd8f13833e6 100644--- a/frontend/src/scenes/authentication/login/variants/legacy/LegacyLogin.tsx+++ b/frontend/src/scenes/authentication/login/variants/legacy/LegacyLogin.tsx@@ -17,6 +17,7 @@ import { Link } from 'lib/lemon-ui/Link'import { Skeleton } from 'lib/ui/quill'import { isEmail } from 'lib/utils'import { AuthShell } from 'scenes/authentication/shared/AuthShell'+import { OtherRegionHint } from 'scenes/authentication/shared/OtherRegionHint'import { RedirectIfLoggedInOtherInstance } from 'scenes/authentication/shared/RedirectToLoggedInInstance'import RegionSelect from 'scenes/authentication/shared/RegionSelect'import { SupportModalButton } from 'scenes/authentication/shared/SupportModalButton'@@ -168,6 +169,7 @@ export function LegacyLogin(): JSX.Element {</></LemonBanner>)}+ {generalError?.code === 'invalid_credentials' && <OtherRegionHint />}{isEmailVerificationSent ? (<div className="deprecated-space-y-4"><div className="flex justify-center">diff --git a/frontend/src/scenes/authentication/shared/OtherRegionHint.tsx b/frontend/src/scenes/authentication/shared/OtherRegionHint.tsxnew file mode 100644index 000000000000..7ea62f170208--- /dev/null+++ b/frontend/src/scenes/authentication/shared/OtherRegionHint.tsx@@ -0,0 +1,47 @@+import { useValues } from 'kea'++import { CLOUD_HOSTNAMES } from 'lib/constants'+import { LemonBanner } from 'lib/lemon-ui/LemonBanner'+import { Link } from 'lib/lemon-ui/Link'+import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'++import { Region } from '~/types'++export function otherRegionOf(region: Region): Region {+ return region === Region.US ? Region.EU : Region.US+}++// Preserve the query string (e.g. `next`) but always land on the login page of the other region.+export function otherRegionLoginUrl(region: Region, search: string): string {+ return `https://${CLOUD_HOSTNAMES[otherRegionOf(region)]}/login${search}`+}++/**+ * Region-aware hint for users who may be authenticating on the wrong PostHog Cloud region (US vs EU).+ *+ * Shown unconditionally whenever it's rendered on cloud — it never checks whether an account actually+ * exists on the other region, so it cannot be used to probe for account existence across regions.+ */+export function OtherRegionHint(): JSX.Element | null {+ const { preflight } = useValues(preflightLogic)++ if (!preflight?.cloud || !preflight?.region) {+ return null+ }++ const otherRegion = otherRegionOf(preflight.region)++ return (+ <LemonBanner type="info">+ Already have a PostHog Cloud account? It may live in our {otherRegion} region — you're currently on{' '}+ {preflight.region}.{' '}+ <Link+ to={otherRegionLoginUrl(preflight.region, location.search)}+ disableClientSideRouting+ data-attr="other-region-login"+ >+ Log in on {CLOUD_HOSTNAMES[otherRegion]}+ </Link>+ </LemonBanner>+ )+}diff --git a/frontend/src/scenes/authentication/shared/otherRegionHint.test.ts b/frontend/src/scenes/authentication/shared/otherRegionHint.test.tsnew file mode 100644index 000000000000..e7219c2d87d4--- /dev/null+++ b/frontend/src/scenes/authentication/shared/otherRegionHint.test.ts@@ -0,0 +1,20 @@+import { otherRegionLoginUrl, otherRegionOf } from 'scenes/authentication/shared/OtherRegionHint'++import { Region } from '~/types'++describe('OtherRegionHint', () => {+ test.each([+ ['US points to EU', Region.US, Region.EU],+ ['EU points to US', Region.EU, Region.US],+ ])('otherRegionOf: %s', (_name, region, expected) => {+ expect(otherRegionOf(region)).toEqual(expected)+ })++ test.each([+ ['US with no query lands on eu login', Region.US, '', 'https://eu.posthog.com/login'],+ ['EU with no query lands on us login', Region.EU, '', 'https://us.posthog.com/login'],+ ['preserves the next query param', Region.US, '?next=/home', 'https://eu.posthog.com/login?next=/home'],+ ])('otherRegionLoginUrl: %s', (_name, region, search, expected) => {+ expect(otherRegionLoginUrl(region, search)).toEqual(expected)+ })+})diff --git a/frontend/src/scenes/organization/ConfirmOrganization/ConfirmOrganization.tsx b/frontend/src/scenes/organization/ConfirmOrganization/ConfirmOrganization.tsxindex 881c902d34fe..655a47f1c1bb 100644--- a/frontend/src/scenes/organization/ConfirmOrganization/ConfirmOrganization.tsx+++ b/frontend/src/scenes/organization/ConfirmOrganization/ConfirmOrganization.tsx@@ -11,6 +11,7 @@ import { LemonButton } from 'lib/lemon-ui/LemonButton'import { LemonDivider } from 'lib/lemon-ui/LemonDivider'import { LemonField } from 'lib/lemon-ui/LemonField'import { LemonInput } from 'lib/lemon-ui/LemonInput/LemonInput'+import { OtherRegionHint } from 'scenes/authentication/shared/OtherRegionHint'import { organizationLogic } from 'scenes/organizationLogic'import { SceneExport } from 'scenes/sceneTypes'@@ -28,6 +29,7 @@ export function ConfirmOrganization(): JSX.Element {return (<BridgePage view="org-creation-confirmation" hedgehog><h2>Create a new organization</h2>+ <OtherRegionHint /><div className="flex-1"><p className="text-center"><strong>diff --git a/playwright/e2e/auth.spec.ts b/playwright/e2e/auth.spec.tsindex a3e7e2a44e9e..742e62f97228 100644--- a/playwright/e2e/auth.spec.ts+++ b/playwright/e2e/auth.spec.ts@@ -69,7 +69,8 @@ test.describe('Auth', () => {await expect(page.locator('[data-attr=password]')).toHaveValue('wrong password')await loginPage.clickLogin()- await expect(page.locator('.LemonBanner')).toContainText('Invalid email or password.')+ // Scope to the error banner: on cloud a separate info banner (OtherRegionHint) also renders here.+ await expect(page.locator('.LemonBanner--error')).toContainText('Invalid email or password.')await loginPage.enterPassword(LOGIN_PASSWORD)await loginPage.clickLogin()