: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
feat(auth): send login error context with support tickets (#91172)
posthog[bot]d515f9167022
diff --git a/frontend/src/scenes/authentication/login/LoginForm.tsx b/frontend/src/scenes/authentication/login/LoginForm.tsxindex 65a132d4ef0f..94d7f59796c8 100644--- a/frontend/src/scenes/authentication/login/LoginForm.tsx+++ b/frontend/src/scenes/authentication/login/LoginForm.tsx@@ -25,13 +25,67 @@ import { RedirectIfLoggedInOtherInstance } from 'scenes/authentication/shared/Reimport { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'import { urls } from 'scenes/urls'-import { LoginMethod } from '~/types'+import { LoginMethod, Region, SSOProvider } from '~/types'import { loginLogic } from './loginLogic'import { SessionRiskBanner } from './SessionRiskBanner'const LAST_LOGIN_METHOD_COOKIE = 'ph_last_login_method'+function loginMethodLabel(method: LoginMethod): string {+ if (method === 'password') {+ return 'password'+ }+ if (method === 'passkey') {+ return 'passkey'+ }+ return method ? SSO_PROVIDER_NAMES[method] : ''+}++// The support form starts empty for the person, so a login-error ticket loses the context the page+// already holds. Prefill the message with the error code, region, and login methods, so support can+// triage without a round trip.+function buildLoginSupportMessage({+ errorCode,+ region,+ ssoEnforcement,+ availableLoginMethods,+ precheckTrusted,+ codeVerificationPending,+}: {+ errorCode?: string+ region?: Region | null+ ssoEnforcement?: SSOProvider | null+ availableLoginMethods: LoginMethod[]+ precheckTrusted: boolean+ codeVerificationPending: boolean+}): string {+ const lines = ['I need help logging in.']+ if (errorCode) {+ lines.push(`Error code: ${errorCode}`)+ }+ if (region) {+ lines.push(`Data region: ${region}`)+ }+ // Only state the account's methods when the precheck is trustworthy. A failed or stale one+ // reports permissive defaults (e.g. password login for an SSO-only account), which would point+ // support the wrong way.+ if (precheckTrusted) {+ if (ssoEnforcement) {+ lines.push(`Login method: SSO enforced (${SSO_PROVIDER_NAMES[ssoEnforcement]})`)+ } else {+ const labels = availableLoginMethods.map(loginMethodLabel).filter(Boolean)+ if (labels.length) {+ lines.push(`Login methods available: ${labels.join(', ')}`)+ }+ }+ }+ if (codeVerificationPending) {+ lines.push('Waiting on an emailed verification code.')+ }+ return lines.join('\n')+}+// Bare text nodes below are wrapped in <span>s: in-page translation replaces text nodes with// <font> elements, which crashes React's sibling insert/remove operations (removeChild /// insertBefore NotFoundError, see react#11538). Text that is its own element's only child is@@ -39,6 +93,7 @@ const LAST_LOGIN_METHOD_COOKIE = 'ph_last_login_method'export function LoginForm(): JSX.Element {const { precheck, exitCodeVerification, resendCodeBasedVerification } = useActions(loginLogic)const { openSupportForm } = useActions(supportLogic)+ const { sendSupportRequest } = useValues(supportLogic)const {precheckResponse,precheckResponseLoading,@@ -54,6 +109,7 @@ export function LoginForm(): JSX.Element {hasNoConfiguredLoginMethod,restrictToProviders,autoRedirectingToProvider,+ availableLoginMethods,} = useValues(loginLogic)const { preflight } = useValues(preflightLogic)@@ -125,9 +181,29 @@ export function LoginForm(): JSX.Element {data-attr="login-error-contact-support"onClick={(e) => {e.preventDefault()+ // Trust the precheck only when it resolved for the email now+ // in the form: a failed precheck reports permissive defaults,+ // and a stale one still holds the previous email's account.+ const precheckTrusted =+ precheckResponse.status === 'completed' &&+ !precheckResponse.precheckFailed &&+ precheckResponse.email === login.emailopenSupportForm({kind: 'support',email: login.email,+ // Prefill only into an empty form. Passing no message lets+ // openSupportForm keep a draft the person already started,+ // so reopening this link never overwrites their text.+ message: sendSupportRequest.message+ ? undefined+ : buildLoginSupportMessage({+ errorCode: generalError.code,+ region: preflight?.region,+ ssoEnforcement: precheckResponse.sso_enforcement,+ availableLoginMethods,+ precheckTrusted,+ codeVerificationPending: codeVerificationRequired,+ }),})}}className="font-semibold no-underline cursor-pointer hover:underline hover:underline-offset-2 text-warning"