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(auth): resume the pending action after passkey re-authentication (#99491)

Rafael Audiberta8fbcb4a5f91
diff --git a/frontend/src/scenes/authentication/shared/passkeyLogic.test.ts b/frontend/src/scenes/authentication/shared/passkeyLogic.test.ts
index 9c7a6be38b0b..e41339880e1d 100644
--- a/frontend/src/scenes/authentication/shared/passkeyLogic.test.ts
+++ b/frontend/src/scenes/authentication/shared/passkeyLogic.test.ts
@@ -1,6 +1,7 @@
import { browserSupportsWebAuthnAutofill, startAuthentication } from '@simplewebauthn/browser'
import { expectLogic } from 'kea-test-utils'
+import { apiStatusLogic } from 'lib/logic/apiStatusLogic'
import { passkeyLogic } from 'scenes/authentication/shared/passkeyLogic'
import { useMocks } from '~/mocks/jest'
@@ -96,4 +97,51 @@ describe('passkeyLogic', () => {
expect(beginHandler).toHaveBeenCalledTimes(1)
})
})
+
+ describe('re-authentication', () => {
+ let logic: ReturnType<typeof passkeyLogic.build>
+
+ beforeEach(() => {
+ ;(startAuthentication as jest.Mock).mockResolvedValue({ id: 'cred-1', response: {} })
+ useMocks({
+ get: { '/api/users/@me/': () => [200, {}] },
+ post: {
+ '/api/webauthn/login/begin/': () => [
+ 200,
+ {
+ challenge: 'abc',
+ timeout: 60000,
+ rpId: 'localhost',
+ allowCredentials: [{ id: 'cred-1', type: 'public-key' }],
+ userVerification: 'required',
+ },
+ ],
+ '/api/webauthn/login/complete/': () => [200, {}],
+ },
+ })
+ initKeaTests()
+ logic = passkeyLogic()
+ logic.mount()
+ })
+
+ afterEach(() => {
+ logic.unmount()
+ jest.clearAllMocks()
+ })
+
+ it('signals the sensitive action waiting on re-authentication', async () => {
+ const onSuccess = jest.fn()
+ const onFailure = jest.fn()
+ // A sensitive action (e.g. inviting members) parks this pair while it awaits re-auth.
+ // Without the signal it stays pending forever and its button spins.
+ apiStatusLogic.actions.setTimeSensitiveAuthenticationRequired([onSuccess, onFailure])
+
+ logic.actions.beginPasskeyLogin(undefined, { reauth: 'true' })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(onSuccess).toHaveBeenCalledTimes(1)
+ expect(onFailure).not.toHaveBeenCalled()
+ expect(apiStatusLogic.values.timeSensitiveAuthenticationRequired).toBe(false)
+ })
+ })
})
diff --git a/frontend/src/scenes/authentication/shared/passkeyLogic.ts b/frontend/src/scenes/authentication/shared/passkeyLogic.ts
index fa22ad2f858f..d898d4ef6b51 100644
--- a/frontend/src/scenes/authentication/shared/passkeyLogic.ts
+++ b/frontend/src/scenes/authentication/shared/passkeyLogic.ts
@@ -6,6 +6,7 @@ import {
import { MakeLogicType, actions, connect, kea, listeners, path, reducers } from 'kea'
import { loaders } from 'kea-loaders'
import { router } from 'kea-router'
+import posthog from 'posthog-js'
import api from 'lib/api'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
@@ -45,6 +46,7 @@ function routeToEmailVerification(e: unknown): boolean {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface passkeyLogicValues {
+ timeSensitiveAuthenticationRequired: boolean | [onSuccess: () => void, onFailure: () => void] // apiStatusLogic
allowCredentialsFromPrecheck: PublicKeyCredentialDescriptorJSON[]
isLoading: boolean
isReauth: boolean
@@ -113,6 +115,7 @@ export type passkeyLogicType = MakeLogicType<passkeyLogicValues, passkeyLogicAct
export const passkeyLogic = kea<passkeyLogicType>([
path(['scenes', 'authentication', 'shared', 'passkeyLogic']),
connect(() => ({
+ values: [apiStatusLogic, ['timeSensitiveAuthenticationRequired']],
actions: [
loginLogic,
['setGeneralError'],
@@ -277,6 +280,10 @@ export const passkeyLogic = kea<passkeyLogicType>([
}
// for reauth, clear authentication required flag
if (values.isReauth) {
+ if (Array.isArray(values.timeSensitiveAuthenticationRequired)) {
+ values.timeSensitiveAuthenticationRequired[0]() // Signal success
+ }
+ posthog.capture('reauthentication_completed', { method: 'passkey' })
actions.setTimeSensitiveAuthenticationRequired(false)
actions.loadUser()
actions.reset()