: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): offer working logins on the no-password login banner (#129505)
Rafael Audibert9a90ed9f08e9
diff --git a/frontend/src/lib/components/SocialLoginButton/SocialLoginButton.tsx b/frontend/src/lib/components/SocialLoginButton/SocialLoginButton.tsxindex a64619d09a8f..eb2474d82b62 100644--- a/frontend/src/lib/components/SocialLoginButton/SocialLoginButton.tsx+++ b/frontend/src/lib/components/SocialLoginButton/SocialLoginButton.tsx@@ -159,6 +159,8 @@ interface SocialLoginButtonsProps {* through `SSOEnforcedLoginButton` instead.*/restrictToProviders?: SSOProvider[] | null+ /** Rendered at the end of the row, after the providers and the passkey. */+ extraButton?: ReactNode}export function SocialLoginButtons({@@ -172,11 +174,12 @@ export function SocialLoginButtons({showPasskey = false,restrictToProviders,onProviderClick,+ extraButton,...props}: SocialLoginButtonsProps): JSX.Element | null {const { preflight, socialAuthAvailable } = useValues(preflightLogic)- if (!preflight || (!socialAuthAvailable && !showPasskey)) {+ if (!preflight || (!socialAuthAvailable && !showPasskey && !extraButton)) {return null}@@ -187,7 +190,7 @@ export function SocialLoginButtons({.sort((a, b) => order.indexOf(a) - order.indexOf(b)): []- if (!socialProviders.length && !showPasskey) {+ if (!socialProviders.length && !showPasskey && !extraButton) {return null}@@ -215,6 +218,7 @@ export function SocialLoginButtons({</Suspense></PasskeyChunkLoadBoundary>)}+ {extraButton}</div>{caption && captionLocation === 'bottom' && <p className="text-secondary">{caption}</p>}</div>diff --git a/frontend/src/scenes/authentication/auth/Auth.stories.tsx b/frontend/src/scenes/authentication/auth/Auth.stories.tsxindex 10b545fb8c19..fcee41724d91 100644--- a/frontend/src/scenes/authentication/auth/Auth.stories.tsx+++ b/frontend/src/scenes/authentication/auth/Auth.stories.tsx@@ -178,6 +178,7 @@ const Template: StoryFn<StoryArgs> = ({password_login_available: !noSignInMethod,},],+ '/api/reset/': () => [200, { success: true }],'/api/signup/precheck': () =>emailTaken? [@@ -308,7 +309,7 @@ SignedOutForSessionRisk.args = { signedOutForSessionRisk: true }export const NoSignInMethod: StoryFn<StoryArgs> = Template.bind({})NoSignInMethod.storyName = 'Account with no sign-in method'-NoSignInMethod.args = { step: 'Login', noSignInMethod: true, googleOAuth: false, github: false, gitlab: false }+NoSignInMethod.args = { step: 'Login', noSignInMethod: true, googleOAuth: true, github: true, gitlab: false }export const PrecheckFailed: StoryFn<StoryArgs> = Template.bind({})PrecheckFailed.storyName = 'Login step when the precheck fails'diff --git a/frontend/src/scenes/authentication/auth/components/EmailStepSocialButtons.tsx b/frontend/src/scenes/authentication/auth/components/EmailStepSocialButtons.tsxindex e566a8bfedfe..e09c4f5e9d4c 100644--- a/frontend/src/scenes/authentication/auth/components/EmailStepSocialButtons.tsx+++ b/frontend/src/scenes/authentication/auth/components/EmailStepSocialButtons.tsx@@ -6,6 +6,7 @@ import { useLastLoginMethod } from 'scenes/authentication/shared/lastLoginMethodimport { authLogic } from '../authLogic'import { PrecheckResponseType, loginLogic } from '../loginLogic'+import { SetPasswordEmailButton } from './SetPasswordEmailButton'// A new person here signs in through the IdP. SAML normally replaces this row, but an account// without a password still needs to see whatever methods it does have.@@ -23,7 +24,8 @@ function hidesLoginRow(export function EmailStepSocialButtons(): JSX.Element | null {const { entry, step, accountExists } = useValues(authLogic)- const { precheckResponse, isPasswordLoginUnavailable, restrictToProviders } = useValues(loginLogic)+ const { precheckResponse, isPasswordLoginUnavailable, restrictToProviders, hasNoConfiguredLoginMethod } =+ useValues(loginLogic)const { preflight } = useValues(preflightLogic)const lastLoginMethod = useLastLoginMethod()@@ -46,6 +48,11 @@ export function EmailStepSocialButtons(): JSX.Element | null {// Once we know the account's methods, only offer a passkey if it actually has// one — otherwise this is the same dead button we're removing.showPasskey={!isPasswordLoginUnavailable || !!precheckResponse.webauthn_credentials?.length}+ extraButton={+ hasNoConfiguredLoginMethod && preflight?.email_service_available ? (+ <SetPasswordEmailButton />+ ) : undefined+ }/>)}diff --git a/frontend/src/scenes/authentication/auth/components/LoginPasswordField.tsx b/frontend/src/scenes/authentication/auth/components/LoginPasswordField.tsxindex a3af99871f37..efd54151eab2 100644--- a/frontend/src/scenes/authentication/auth/components/LoginPasswordField.tsx+++ b/frontend/src/scenes/authentication/auth/components/LoginPasswordField.tsx@@ -12,8 +12,15 @@ import { loginLogic } from '../loginLogic'export function LoginPasswordField(): JSX.Element {const { accountExists, isLoginPasswordHidden } = useValues(authLogic)- const { login, loginErrors, precheckResponse, hasNoConfiguredLoginMethod, autoRedirectingToProvider } =- useValues(loginLogic)+ const {+ login,+ loginErrors,+ precheckResponse,+ hasNoConfiguredLoginMethod,+ autoRedirectingToProvider,+ setPasswordLinkSentTo,+ preflight,+ } = useValues(loginLogic)const { setLoginValue } = useActions(loginLogic)return (@@ -56,21 +63,26 @@ export function LoginPasswordField(): JSX.Element {There's no account for this email. Ask your PostHog admin for an invite.</AuthBanner>)}- {hasNoConfiguredLoginMethod && (- <AuthBanner variant="warning">- <span>No sign-in method is set up for this account. Use</span>{' '}- <Link- to={[urls.passwordReset(), { email: login.email }]}- // Autocapture reports the click. Each reset entry point has its- // own `data-attr`, so one funnel can tell them apart.- data-attr="login-no-method-reset-password"- className="font-semibold no-underline cursor-pointer hover:underline hover:underline-offset-2 text-warning"- >- Forgot password?- </Link>{' '}- <span>to set a password by email.</span>- </AuthBanner>- )}+ {hasNoConfiguredLoginMethod &&+ (setPasswordLinkSentTo === login.email ? (+ <AuthBanner variant="success">+ <span>We sent a link to </span>+ <strong className="break-all">{login.email}</strong>+ <span>. Open it to set your password, then log in.</span>+ </AuthBanner>+ ) : preflight?.email_service_available ? (+ <AuthBanner variant="warning">+ This account doesn't have a password yet. Log in with one of the options below, or get an email+ to set a password.+ </AuthBanner>+ ) : (+ <AuthBanner variant="warning">+ <span>This account doesn't have a password yet, and this instance can't send email. </span>+ <Link to={[urls.passwordReset(), { email: login.email }]} data-attr="login-no-method-no-email">+ See how to get access+ </Link>+ </AuthBanner>+ ))}{autoRedirectingToProvider && (<p className="text-sm text-secondary text-center mb-0">Redirecting to {SSO_PROVIDER_NAMES[autoRedirectingToProvider]}…diff --git a/frontend/src/scenes/authentication/auth/components/SetPasswordEmailButton.tsx b/frontend/src/scenes/authentication/auth/components/SetPasswordEmailButton.tsxnew file mode 100644index 000000000000..92ec8c474eb4--- /dev/null+++ b/frontend/src/scenes/authentication/auth/components/SetPasswordEmailButton.tsx@@ -0,0 +1,27 @@+import { useActions, useValues } from 'kea'++import { IconLetter } from '@posthog/icons'++import { LemonButton } from 'lib/lemon-ui/LemonButton'++import { loginLogic } from '../loginLogic'++export function SetPasswordEmailButton(): JSX.Element {+ const { login, setPasswordLinkSentToLoading } = useValues(loginLogic)+ const { sendSetPasswordLink } = useActions(loginLogic)++ return (+ <LemonButton+ size="large"+ icon={<IconLetter className="w-7 h-7" />}+ tooltip="Email me a link to set a password"+ aria-label="Email me a link to set a password"+ htmlType="button"+ // Autocapture reports the click. Each reset entry point has its own `data-attr`, so one+ // funnel can tell them apart.+ data-attr="login-no-method-reset-password"+ loading={setPasswordLinkSentToLoading}+ onClick={() => sendSetPasswordLink(login.email)}+ />+ )+}diff --git a/frontend/src/scenes/authentication/auth/loginLogic.test.ts b/frontend/src/scenes/authentication/auth/loginLogic.test.tsindex 548fba065148..514949136120 100644--- a/frontend/src/scenes/authentication/auth/loginLogic.test.ts+++ b/frontend/src/scenes/authentication/auth/loginLogic.test.ts@@ -340,12 +340,14 @@ describe('loginLogic', () => {describe('available login methods', () => {let logic: ReturnType<typeof loginLogic.build>let precheckResponse: Record<string, any>+ let resetHandler: jest.Mockconst originalVendor = window.navigator.vendorbeforeEach(() => {setVendor(WEBKIT_VENDOR) // skip the passkey auto-trigger, isolate the precheck responseprecheckResponse = { saml_available: false }- useMocks({ post: { '/api/login/precheck': () => [200, precheckResponse] } })+ resetHandler = jest.fn(() => [200, { success: true }])+ useMocks({ post: { '/api/login/precheck': () => [200, precheckResponse], '/api/reset/': resetHandler } })initKeaTests()router.actions.push('/login')logic = loginLogic()@@ -358,9 +360,10 @@ describe('loginLogic', () => {jest.clearAllMocks()})- async function precheck(response: Record<string, any>): Promise<void> {+ async function precheck(response: Record<string, any>, email = '[email protected]'): Promise<void> {precheckResponse = response- logic.actions.precheck({ email: '[email protected]' })+ logic.actions.setLoginValues({ email })+ logic.actions.precheck({ email })await expectLogic(logic).toDispatchActions(['precheckSuccess']).toFinishAllListeners()}@@ -406,7 +409,7 @@ describe('loginLogic', () => {})expect(logic.values.availableLoginMethods).toEqual(['passkey'])expect(logic.values.hasNoConfiguredLoginMethod).toBe(false)- expect(logic.values.restrictToProviders).toEqual([])+ expect(logic.values.restrictToProviders).toBe(null)})it('offers SAML for a passwordless account on a SAML domain', async () => {@@ -426,11 +429,28 @@ describe('loginLogic', () => {expect(logic.values.hasNoConfiguredLoginMethod).toBe(false)})- it('reports a dead end for a passwordless account with nothing else', async () => {+ it('offers every provider and a set-password email to a passwordless account with nothing linked', async () => {await precheck({ saml_available: false, password_login_available: false, social_providers: [] })expect(logic.values.isPasswordLoginUnavailable).toBe(true)expect(logic.values.availableLoginMethods).toEqual([])expect(logic.values.hasNoConfiguredLoginMethod).toBe(true)+ expect(logic.values.restrictToProviders).toBe(null)++ logic.actions.sendSetPasswordLink('[email protected]')+ await expectLogic(logic).toDispatchActions(['sendSetPasswordLinkSuccess'])++ expect(resetHandler).toHaveBeenCalledTimes(1)+ expect(logic.values.setPasswordLinkSentTo).toBe('[email protected]')+ })++ it('ignores a passwordless precheck once the email in the field changes', async () => {+ await precheck({ saml_available: false, password_login_available: false, social_providers: [] })++ logic.actions.setLoginValues({ email: '[email protected]' })++ expect(logic.values.isPasswordLoginUnavailable).toBe(false)+ expect(logic.values.hasNoConfiguredLoginMethod).toBe(false)+ expect(logic.values.restrictToProviders).toBe(null)})it('defers entirely to enforced SSO', async () => {diff --git a/frontend/src/scenes/authentication/auth/loginLogic.ts b/frontend/src/scenes/authentication/auth/loginLogic.tsindex e0ebd037f8b2..3c48705fa306 100644--- a/frontend/src/scenes/authentication/auth/loginLogic.ts+++ b/frontend/src/scenes/authentication/auth/loginLogic.ts@@ -10,6 +10,7 @@ import posthog from 'posthog-js'import api from 'lib/api'import { ApiError } from 'lib/api-error'import { getSocialLoginUrl } from 'lib/components/SocialLoginButton/socialLoginUrl'+import { SSO_PROVIDER_NAMES } from 'lib/constants'import { lemonToast } from 'lib/lemon-ui/LemonToast'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { preflightLogic } from 'lib/logic/preflightLogic'@@ -119,6 +120,7 @@ export interface loginLogicValues {detail: string} | nullhasNoConfiguredLoginMethod: boolean+ instanceSocialProviders: SSOProvider[]isCodeVerificationSubmitting: booleanisCodeVerificationValid: booleanisLoginSubmitting: boolean@@ -142,6 +144,8 @@ export interface loginLogicValues {} | nullresendResponseLoading: booleanrestrictToProviders: SSOProvider[] | null+ setPasswordLinkSentTo: string | null+ setPasswordLinkSentToLoading: booleanshowCodeVerificationErrors: booleanshowLoginErrors: booleanwasSignedOutForSessionRisk: boolean@@ -212,6 +216,21 @@ export interface loginLogicActions {resetLogin: (values?: LoginForm) => {values?: LoginForm}+ sendSetPasswordLink: (email: string) => string+ sendSetPasswordLinkFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ sendSetPasswordLinkSuccess: (+ setPasswordLinkSentTo: string,+ payload?: string+ ) => {+ setPasswordLinkSentTo: string+ payload?: string+ }setCodeVerificationManualErrors: (errors: Record<string, any>) => {errors: Record<string, any>}@@ -298,7 +317,7 @@ export interface loginLogicActions {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface loginLogicMeta {__keaTypeGenInternalSelectorTypes: {- isPasswordLoginUnavailable: (precheckResponse: PrecheckResponseType) => boolean+ isPasswordLoginUnavailable: (precheckResponse: PrecheckResponseType, login: LoginForm) => booleanavailableLoginMethods: (precheckResponse: PrecheckResponseType) => LoginMethod[]hasNoConfiguredLoginMethod: (precheckResponse: PrecheckResponseType,@@ -309,6 +328,7 @@ export interface loginLogicMeta {precheckResponse: PrecheckResponseType,isPasswordLoginUnavailable: boolean) => SSOProvider[] | null+ instanceSocialProviders: (preflight: PreflightStatus | null) => SSOProvider[]wasSignedOutForSessionRisk: (searchParams: Record<string, any>) => boolean}}@@ -444,6 +464,23 @@ export const loginLogic = kea<loginLogicType>([},},],+ setPasswordLinkSentTo: [+ null as string | null,+ {+ sendSetPasswordLink: async (email: string, breakpoint) => {+ breakpoint()+ try {+ // A reset link on an account without a password sets its first password.+ // nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. No generated function covers this endpoint yet. Find out why the generated client skips it (no schema, no product tag, or excluded from the spec) and fix that first.+ await api.create('api/reset/', { email })+ return email+ } catch (e) {+ lemonToast.error("Couldn't send the email. Wait a minute, then try again.")+ throw e+ }+ },+ },+ ],resendResponse: [null as { success: boolean; message: string } | null,{@@ -467,66 +504,6 @@ export const loginLogic = kea<loginLogicType>([},],})),- selectors(() => ({- // True only when we know this account exists and has no usable password, so every variant- // hides the password field for the same reason. The explicit `=== false` matters: an older- // server or a failed precheck omits the field, and those must keep the password box.- // (Variants still decide for themselves whether to hide it while precheck is in flight.)- isPasswordLoginUnavailable: [- (s) => [s.precheckResponse],- (precheckResponse: PrecheckResponseType): boolean => precheckResponse.password_login_available === false,- ],- // Every way this specific account can get in. Empty until precheck resolves, and empty when- // SSO is enforced (that path takes over the whole form).- availableLoginMethods: [- (s) => [s.precheckResponse],- (precheckResponse: PrecheckResponseType): LoginMethod[] => {- if (precheckResponse.status !== 'completed' || precheckResponse.sso_enforcement) {- return []- }- const methods: LoginMethod[] = []- if (precheckResponse.password_login_available !== false) {- methods.push('password')- }- for (const provider of precheckResponse.social_providers ?? []) {- methods.push(provider)- }- if (precheckResponse.saml_available && !methods.includes('saml')) {- methods.push('saml')- }- if (precheckResponse.oidc_available && !methods.includes('oidc')) {- methods.push('oidc')- }- if (precheckResponse.webauthn_credentials?.length) {- methods.push('passkey')- }- return methods- },- ],- // A passwordless account with nothing else linked. They can only get back in via a reset.- hasNoConfiguredLoginMethod: [- (s) => [s.precheckResponse, s.isPasswordLoginUnavailable, s.availableLoginMethods],- (- precheckResponse: PrecheckResponseType,- isPasswordLoginUnavailable: boolean,- availableLoginMethods: LoginMethod[]- ): boolean =>- // `availableLoginMethods` is deliberately empty when SSO is enforced — that path owns- // the whole form, so it isn't a dead end.- !precheckResponse.sso_enforcement && isPasswordLoginUnavailable && availableLoginMethods.length === 0,- ],- // Allowlist for the social button row: only narrow it once we know the account is passwordless- // and which providers it has. `null` means "show everything the instance offers", as before.- restrictToProviders: [- (s) => [s.precheckResponse, s.isPasswordLoginUnavailable],- (precheckResponse: PrecheckResponseType, isPasswordLoginUnavailable: boolean): SSOProvider[] | null =>- isPasswordLoginUnavailable ? (precheckResponse.social_providers ?? []) : null,- ],- wasSignedOutForSessionRisk: [- () => [router.selectors.searchParams],- (searchParams: Record<string, string>): boolean => searchParams['reason'] === 'session_risk',- ],- })),forms(({ actions, values }) => ({login: {defaults: { email: '', password: '' } as LoginForm,@@ -606,6 +583,86 @@ export const loginLogic = kea<loginLogicType>([},},})),+ selectors(() => ({+ // True only when we know this account exists and has no usable password, so every variant+ // hides the password field for the same reason. The explicit `=== false` matters: an older+ // server or a failed precheck omits the field, and those must keep the password box.+ // (Variants still decide for themselves whether to hide it while precheck is in flight.)+ // The precheck must also be for the email now in the field. Otherwise the result for an+ // earlier or autofilled address hides the password of the account the person corrected to.+ isPasswordLoginUnavailable: [+ (s) => [s.precheckResponse, s.login],+ (precheckResponse: PrecheckResponseType, login: LoginForm): boolean =>+ precheckResponse.password_login_available === false && precheckResponse.email === login.email,+ ],+ // Every way this specific account can get in. Empty until precheck resolves, and empty when+ // SSO is enforced (that path takes over the whole form).+ availableLoginMethods: [+ (s) => [s.precheckResponse],+ (precheckResponse: PrecheckResponseType): LoginMethod[] => {+ if (precheckResponse.status !== 'completed' || precheckResponse.sso_enforcement) {+ return []+ }+ const methods: LoginMethod[] = []+ if (precheckResponse.password_login_available !== false) {+ methods.push('password')+ }+ for (const provider of precheckResponse.social_providers ?? []) {+ methods.push(provider)+ }+ if (precheckResponse.saml_available && !methods.includes('saml')) {+ methods.push('saml')+ }+ if (precheckResponse.oidc_available && !methods.includes('oidc')) {+ methods.push('oidc')+ }+ if (precheckResponse.webauthn_credentials?.length) {+ methods.push('passkey')+ }+ return methods+ },+ ],+ // A passwordless account with nothing else linked.+ hasNoConfiguredLoginMethod: [+ (s) => [s.precheckResponse, s.isPasswordLoginUnavailable, s.availableLoginMethods],+ (+ precheckResponse: PrecheckResponseType,+ isPasswordLoginUnavailable: boolean,+ availableLoginMethods: LoginMethod[]+ ): boolean =>+ // `availableLoginMethods` is deliberately empty when SSO is enforced — that path owns+ // the whole form, so it isn't a dead end.+ !precheckResponse.sso_enforcement && isPasswordLoginUnavailable && availableLoginMethods.length === 0,+ ],+ // Allowlist for the social button row: only narrow it once we know the account is passwordless+ // and has linked providers. `null` means "show everything the instance offers". A passwordless+ // account with no linked provider also gets every provider, because the social login pipeline+ // links an existing account by verified email on its first sign-in.+ restrictToProviders: [+ (s) => [s.precheckResponse, s.isPasswordLoginUnavailable],+ (precheckResponse: PrecheckResponseType, isPasswordLoginUnavailable: boolean): SSOProvider[] | null =>+ isPasswordLoginUnavailable && precheckResponse.social_providers?.length+ ? precheckResponse.social_providers+ : null,+ ],+ instanceSocialProviders: [+ (s) => [s.preflight],+ (preflight: PreflightStatus | null): SSOProvider[] => {+ const order = Object.keys(SSO_PROVIDER_NAMES)+ return (+ (Object.entries(preflight?.available_social_auth_providers ?? {}) as [SSOProvider, boolean][])+ // SAML and OIDC are domain-configured and never render as a social button.+ .filter(([provider, available]) => available && provider !== 'saml' && provider !== 'oidc')+ .map(([provider]) => provider)+ .sort((a, b) => order.indexOf(a) - order.indexOf(b))+ )+ },+ ],+ wasSignedOutForSessionRisk: [+ () => [router.selectors.searchParams],+ (searchParams: Record<string, string>): boolean => searchParams['reason'] === 'session_risk',+ ],+ })),listeners(({ values, actions }) => ({submitLoginSuccess: () => {// A logged-in session reads the address from the user, so drop the stored onediff --git a/frontend/src/scenes/authentication/shared/loginTelemetryLogic.test.ts b/frontend/src/scenes/authentication/shared/loginTelemetryLogic.test.tsindex 518e1138a661..61b1eeb360a1 100644--- a/frontend/src/scenes/authentication/shared/loginTelemetryLogic.test.ts+++ b/frontend/src/scenes/authentication/shared/loginTelemetryLogic.test.ts@@ -2,6 +2,7 @@ import { router } from 'kea-router'import { expectLogic } from 'kea-test-utils'import posthog from 'posthog-js'+import { authLogic } from 'scenes/authentication/auth/authLogic'import { loginLogic } from 'scenes/authentication/auth/loginLogic'import { login2FALogic } from 'scenes/authentication/login-2fa/login2FALogic'import { passwordResetLogic } from 'scenes/authentication/password-reset/passwordResetLogic'@@ -33,6 +34,8 @@ const LISTENED_ACTION_SOURCES: Record<keyof typeof LISTENED_ACTIONS, () => strincodeVerificationFailure: () => loginLogic.actionTypes.submitCodeVerificationFailure,twoFactorError: () => login2FALogic.actionTypes.setGeneralError,resetRequested: () => passwordResetLogic.actionTypes.submitRequestPasswordResetSuccess,+ accountPathChosen: () => authLogic.actionTypes.chooseAccountPath,+ setPasswordLinkSent: () => loginLogic.actionTypes.sendSetPasswordLinkSuccess,}describe('loginTelemetryLogic', () => {@@ -124,6 +127,42 @@ describe('loginTelemetryLogic', () => {expect(captureCount('password reset requested')).toBe(1)})+ it('reports the no-method banner once per email on the login step, and the email it leads to', async () => {+ precheckHandler.mockImplementation(() => [+ 200,+ { saml_available: false, password_login_available: false, social_providers: [] },+ ])+ const auth = authLogic()+ auth.mount()+ login.actions.setLoginValues({ email: '[email protected]' })+ login.actions.precheck({ email: '[email protected]' })+ await expectLogic(login).toDispatchActions(['precheckSuccess']).toFinishAllListeners()++ expect(captureCount('login no method shown')).toBe(0)++ auth.actions.continueWithEmail()+ await expectLogic(auth).toDispatchActions(['chooseAccountPath']).toFinishAllListeners()+ auth.actions.backToEmail()+ auth.actions.continueWithEmail()+ await expectLogic(auth).toDispatchActions(['chooseAccountPath']).toFinishAllListeners()+ auth.unmount()++ login.actions.sendSetPasswordLink('[email protected]')+ await expectLogic(login).toDispatchActions(['sendSetPasswordLinkSuccess']).toFinishAllListeners()++ expect(captureCount('login no method shown')).toBe(1)+ expect(capturedProperties('password reset requested')).toMatchObject({ source: 'login_no_method' })+ })++ it('does not report a set-password email that the server refused', async () => {+ useMocks({ post: { '/api/reset/': () => [429, { detail: 'Request was throttled.' }] } })++ login.actions.sendSetPasswordLink('[email protected]')+ await expectLogic(login).toDispatchActions(['sendSetPasswordLinkFailure']).toFinishAllListeners()++ expect(captureCount('password reset requested')).toBe(0)+ })+// The server redirects a failed SSO sign-in back to /login?error_code=..., and kea-router replays// that URL while loginLogic mounts, before this logic exists. That is the case where the person// is most stuck, so it must not fall through the gap.@@ -168,13 +207,16 @@ describe('loginTelemetryLogic', () => {(key) => {const twoFA = login2FALogic()const reset = passwordResetLogic()+ const auth = authLogic()twoFA.mount()reset.mount()+ auth.mount()expect(LISTENED_ACTIONS[key]).toBe(LISTENED_ACTION_SOURCES[key]())twoFA.unmount()reset.unmount()+ auth.unmount()})@@ -189,6 +231,7 @@ describe('loginTelemetryLogic', () => {expect(loginLogic.findMounted()).toBeNull()expect(login2FALogic.findMounted()).toBeNull()expect(passwordResetLogic.findMounted()).toBeNull()+ expect(authLogic.findMounted()).toBeNull()// afterEach unmounts both logics, so restore the one the test took downlogin = loginLogic()diff --git a/frontend/src/scenes/authentication/shared/loginTelemetryLogic.ts b/frontend/src/scenes/authentication/shared/loginTelemetryLogic.tsindex e8f29c62d6c6..b358e20003b7 100644--- a/frontend/src/scenes/authentication/shared/loginTelemetryLogic.ts+++ b/frontend/src/scenes/authentication/shared/loginTelemetryLogic.ts@@ -19,6 +19,8 @@ export type LoginFailureStep = 'login' | 'passkey' | 'code' | '2fa'*/let reportedError: { code: string; detail: string } | null = null+let reportedNoMethodEmail: string | null = null+/*** The actions this logic listens to, named by their kea action type strings.*@@ -37,6 +39,8 @@ export const LISTENED_ACTIONS = {codeVerificationFailure: 'submit code verification failure (scenes.authentication.auth.loginLogic)',twoFactorError: 'set general error (scenes.authentication.login-2fa.login2FALogic)',resetRequested: 'submit request password reset success (scenes.authentication.password-reset.passwordResetLogic)',+ accountPathChosen: 'choose account path (scenes.authentication.auth.authLogic)',+ setPasswordLinkSent: 'send set password link success (scenes.authentication.auth.loginLogic)',} as const// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -103,6 +107,29 @@ export const loginTelemetryLogic = kea<loginTelemetryLogicType>([[LISTENED_ACTIONS.resetRequested]: () => {posthog.capture('password reset requested', { region: values.preflight?.region })},+ // The banner renders only on the login step, and an edit to the email returns the page to the+ // email step. So the login step, not the precheck, is when the person sees it. Report it once+ // per email, because "Back" and Continue reach the same login step again.+ [LISTENED_ACTIONS.accountPathChosen]: ({ accountPath }: { accountPath: string }) => {+ const login = loginLogic.findMounted()+ if (+ accountPath !== 'login' ||+ !login?.values.hasNoConfiguredLoginMethod ||+ login.values.login.email === reportedNoMethodEmail+ ) {+ return+ }+ reportedNoMethodEmail = login.values.login.email+ // pinned: analytics event name and property names+ posthog.capture('login no method shown', {+ region: values.preflight?.region,+ social_providers_offered: login.values.instanceSocialProviders,+ })+ },+ [LISTENED_ACTIONS.setPasswordLinkSent]: () => {+ // pinned: analytics event name and property names+ posthog.capture('password reset requested', { region: values.preflight?.region, source: 'login_no_method' })+ },})),])