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(passkeys): stop re-throwing expected WebAuthn cancellations (#60426)

posthog[bot]12d21db557d1
diff --git a/frontend/src/scenes/authentication/login2FALogic.ts b/frontend/src/scenes/authentication/login2FALogic.ts
index b655915d83eb..804b35501921 100644
--- a/frontend/src/scenes/authentication/login2FALogic.ts
+++ b/frontend/src/scenes/authentication/login2FALogic.ts
@@ -6,7 +6,7 @@ import { loaders } from 'kea-loaders'
import api, { ApiError } from 'lib/api'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
-import { getPasskeyErrorMessage } from 'scenes/settings/user/passkeys/utils'
+import { getPasskeyErrorMessage, isWebAuthnCancellation } from 'scenes/settings/user/passkeys/utils'
import type { login2FALogicType } from './login2FALogicType'
import { handleLoginRedirect } from './loginLogic'
@@ -45,6 +45,7 @@ export const login2FALogic = kea<login2FALogicType>([
setLoginStep: (step: LoginStep) => ({ step }),
clearGeneralError: true,
beginPasskey2FA: true,
+ passkey2FACancelled: true,
checkPasskeysAvailable: true,
setTotpAvailable: (available: boolean) => ({ available }),
}),
@@ -62,6 +63,13 @@ export const login2FALogic = kea<login2FALogicType>([
setTotpAvailable: (_, { available }) => available,
},
],
+ passkey2FAWasCancelled: [
+ false,
+ {
+ beginPasskey2FA: () => false,
+ passkey2FACancelled: () => true,
+ },
+ ],
}),
loaders(({ actions }) => ({
passkey2FA: [
@@ -93,6 +101,12 @@ export const login2FALogic = kea<login2FALogicType>([
return null
} catch (e: unknown) {
+ if (isWebAuthnCancellation(e)) {
+ // Expected user cancellation — fully swallow so it
+ // doesn't surface in the UI or in error tracking.
+ actions.passkey2FACancelled()
+ return null
+ }
actions.setGeneralError('passkey_error', getPasskeyErrorMessage(e))
throw e
}
@@ -139,18 +153,25 @@ export const login2FALogic = kea<login2FALogicType>([
},
},
})),
- listeners({
+ listeners(({ values }) => ({
submitTwofactortokenSuccess: () => {
handleLoginRedirect()
// Reload the page after login to ensure POSTHOG_APP_CONTEXT is set correctly.
window.location.reload()
},
beginPasskey2FASuccess: () => {
+ // The loader returns null on user cancellation to avoid surfacing
+ // the DOMException to global error capture. Skip the post-login
+ // redirect/reload path in that case so the user stays on the
+ // 2FA screen and can retry.
+ if (values.passkey2FAWasCancelled) {
+ return
+ }
handleLoginRedirect()
// Reload the page after login to ensure POSTHOG_APP_CONTEXT is set correctly.
window.location.reload()
},
- }),
+ })),
afterMount(({ actions }) => {
// Check if user has passkeys when component mounts
actions.checkPasskeysAvailable()
diff --git a/frontend/src/scenes/authentication/passkeyLogic.ts b/frontend/src/scenes/authentication/passkeyLogic.ts
index c7164fd405c8..09751bd5bad9 100644
--- a/frontend/src/scenes/authentication/passkeyLogic.ts
+++ b/frontend/src/scenes/authentication/passkeyLogic.ts
@@ -1,15 +1,11 @@
-import {
- type PublicKeyCredentialDescriptorJSON,
- type WebAuthnError,
- startAuthentication,
-} from '@simplewebauthn/browser'
+import { type PublicKeyCredentialDescriptorJSON, startAuthentication } from '@simplewebauthn/browser'
import { actions, connect, kea, listeners, path, reducers } from 'kea'
import { loaders } from 'kea-loaders'
import { router } from 'kea-router'
import api from 'lib/api'
import { apiStatusLogic } from 'lib/logic/apiStatusLogic'
-import { getPasskeyErrorMessage } from 'scenes/settings/user/passkeys/utils'
+import { getPasskeyErrorMessage, isWebAuthnCancellation } from 'scenes/settings/user/passkeys/utils'
import { userLogic } from 'scenes/userLogic'
import { handleLoginRedirect, loginLogic } from './loginLogic'
@@ -47,6 +43,7 @@ export const passkeyLogic = kea<passkeyLogicType>([
params?: BeginPasskeyLoginParams
) => ({ allowCredentials, params }),
startPasskeyAuthentication: true,
+ passkeyAuthenticationCancelled: true,
reset: true,
}),
reducers({
@@ -79,6 +76,13 @@ export const passkeyLogic = kea<passkeyLogicType>([
reset: () => false,
},
],
+ wasCancelled: [
+ false,
+ {
+ beginPasskeyLogin: () => false,
+ passkeyAuthenticationCancelled: () => true,
+ },
+ ],
}),
loaders(({ values, actions }) => ({
loginWithPasskey: [
@@ -110,24 +114,13 @@ export const passkeyLogic = kea<passkeyLogicType>([
return null
} catch (e: unknown) {
- // Only set error if it's not a user cancellation (those are expected)
- if (e && typeof e === 'object' && 'name' in e) {
- const errorName = (e as WebAuthnError).name
- if (errorName !== 'NotAllowedError' && errorName !== 'AbortError') {
- actions.setGeneralError('passkey_error', getPasskeyErrorMessage(e))
- }
- } else if (e && typeof e === 'object' && 'error' in e) {
- const nestedError = (e as { error?: WebAuthnError }).error
- if (
- nestedError?.name &&
- nestedError.name !== 'NotAllowedError' &&
- nestedError.name !== 'AbortError'
- ) {
- actions.setGeneralError('passkey_error', getPasskeyErrorMessage(e))
- }
- } else {
- actions.setGeneralError('passkey_error', getPasskeyErrorMessage(e))
+ if (isWebAuthnCancellation(e)) {
+ // Expected user cancellation — fully swallow so it
+ // doesn't surface in the UI or in error tracking.
+ actions.passkeyAuthenticationCancelled()
+ return null
}
+ actions.setGeneralError('passkey_error', getPasskeyErrorMessage(e))
throw e
}
},
@@ -140,6 +133,14 @@ export const passkeyLogic = kea<passkeyLogicType>([
actions.startPasskeyAuthentication()
},
startPasskeyAuthenticationSuccess: async () => {
+ // The loader returns null on user cancellation to avoid surfacing
+ // the DOMException to global error capture. Skip the post-login
+ // redirect/reload path in that case so the user stays on the
+ // login screen and can retry.
+ if (values.wasCancelled) {
+ actions.reset()
+ return
+ }
// for reauth, clear authentication required flag
if (values.isReauth) {
actions.setTimeSensitiveAuthenticationRequired(false)
@@ -158,8 +159,8 @@ export const passkeyLogic = kea<passkeyLogicType>([
window.location.reload()
},
startPasskeyAuthenticationFailure: () => {
- // When passkey authentication fails (user cancels, etc.), reset state
- // This allows the normal login flow to continue (e.g., password + 2FA)
+ // Reset state on real authentication failures so the user can fall
+ // back to the normal login flow (e.g., password + 2FA).
actions.reset()
},
})),
diff --git a/frontend/src/scenes/authentication/signup/signupForm/signupLogic.ts b/frontend/src/scenes/authentication/signup/signupForm/signupLogic.ts
index 72afd44dbf52..bcb6672d3244 100644
--- a/frontend/src/scenes/authentication/signup/signupForm/signupLogic.ts
+++ b/frontend/src/scenes/authentication/signup/signupForm/signupLogic.ts
@@ -12,7 +12,7 @@ import { CLOUD_HOSTNAMES, FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { getRelativeNextPath } from 'lib/utils'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
-import { getPasskeyErrorMessage } from 'scenes/settings/user/passkeys/utils'
+import { getPasskeyErrorMessage, isWebAuthnCancellation } from 'scenes/settings/user/passkeys/utils'
import { RegistrationBeginResponse } from 'scenes/settings/user/passkeySettingsLogic'
import { urls } from 'scenes/urls'
@@ -615,7 +615,9 @@ export const signupLogic = kea<signupLogicType>([
actions.setPasskeyRegistered(true)
actions.setSignupPanelAuthValue('password', '') // Clear password since we're using passkey
} catch (e: any) {
- actions.setPasskeyError(getPasskeyErrorMessage(e, 'Failed to register passkey. Please try again.'))
+ if (!isWebAuthnCancellation(e)) {
+ actions.setPasskeyError(getPasskeyErrorMessage(e, 'Failed to register passkey. Please try again.'))
+ }
} finally {
actions.setPasskeyRegistering(false)
}
diff --git a/frontend/src/scenes/settings/user/passkeys/utils.test.ts b/frontend/src/scenes/settings/user/passkeys/utils.test.ts
new file mode 100644
index 000000000000..3815f229e9b3
--- /dev/null
+++ b/frontend/src/scenes/settings/user/passkeys/utils.test.ts
@@ -0,0 +1,19 @@
+import { isWebAuthnCancellation } from './utils'
+
+describe('isWebAuthnCancellation', () => {
+ it.each([
+ ['plain NotAllowedError', { name: 'NotAllowedError' }, true],
+ ['plain AbortError', { name: 'AbortError' }, true],
+ ['DOMException-like NotAllowedError', new DOMException('cancelled', 'NotAllowedError'), true],
+ ['nested SimpleWebAuthn-style cancellation', { error: { name: 'NotAllowedError' } }, true],
+ ['nested SimpleWebAuthn-style abort', { error: { name: 'AbortError' } }, true],
+ ['unrelated error name', { name: 'InvalidStateError' }, false],
+ ['nested unrelated error name', { error: { name: 'InvalidStateError' } }, false],
+ ['plain Error', new Error('boom'), false],
+ ['string', 'NotAllowedError', false],
+ ['null', null, false],
+ ['undefined', undefined, false],
+ ])('returns the right answer for %s', (_label, input, expected) => {
+ expect(isWebAuthnCancellation(input)).toBe(expected)
+ })
+})
diff --git a/frontend/src/scenes/settings/user/passkeys/utils.ts b/frontend/src/scenes/settings/user/passkeys/utils.ts
index ffd3d226e765..5581be6b1d13 100644
--- a/frontend/src/scenes/settings/user/passkeys/utils.ts
+++ b/frontend/src/scenes/settings/user/passkeys/utils.ts
@@ -5,6 +5,24 @@ const WEBAUTHN_ERROR_MESSAGES: Record<string, string> = {
AbortError: 'Operation was cancelled.',
}
+const WEBAUTHN_CANCELLATION_ERROR_NAMES = new Set(['NotAllowedError', 'AbortError'])
+
+// SimpleWebAuthn surfaces user cancellations and authenticator timeouts as
+// `NotAllowedError`/`AbortError`, sometimes wrapped under an `error` property.
+// These are expected outcomes — never display them as errors or capture them
+// in exception tracking.
+export function isWebAuthnCancellation(error: unknown): boolean {
+ if (!error || typeof error !== 'object') {
+ return false
+ }
+ const name = (error as { name?: unknown }).name
+ if (typeof name === 'string' && WEBAUTHN_CANCELLATION_ERROR_NAMES.has(name)) {
+ return true
+ }
+ const nestedName = (error as { error?: { name?: unknown } }).error?.name
+ return typeof nestedName === 'string' && WEBAUTHN_CANCELLATION_ERROR_NAMES.has(nestedName)
+}
+
export function getPasskeyErrorMessage(error: any, defaultMessage?: string): string {
if (error?.name && WEBAUTHN_ERROR_MESSAGES[error.name]) {
return WEBAUTHN_ERROR_MESSAGES[error.name]