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: don't reject re-auth promise with undefined on dismissal (#68797)

Alex Liderce841e147092
diff --git a/frontend/src/lib/components/TimeSensitiveAuthentication/timeSensitiveAuthenticationLogic.test.ts b/frontend/src/lib/components/TimeSensitiveAuthentication/timeSensitiveAuthenticationLogic.test.ts
index 4f2e2fad4170..26476441ffe0 100644
--- a/frontend/src/lib/components/TimeSensitiveAuthentication/timeSensitiveAuthenticationLogic.test.ts
+++ b/frontend/src/lib/components/TimeSensitiveAuthentication/timeSensitiveAuthenticationLogic.test.ts
@@ -134,5 +134,22 @@ describe('timeSensitiveAuthenticationLogic', () => {
showAuthenticationModal: true,
})
})
+
+ it('should settle a pending checkReauthentication when the modal is dismissed', async () => {
+ userLogic.actions.loadUserSuccess({
+ ...MOCK_DEFAULT_USER,
+ sensitive_session_expires_at: dayjs().add(4, 'minutes').toISOString(),
+ })
+
+ const pending = logic.asyncActions.checkReauthentication()
+ expect(logic.values.showAuthenticationModal).toBe(true) // guard: the check is actually pending on the modal
+ logic.actions.setDismissedReauthentication(true)
+
+ // Rejects (TypeError on undefined.message in kea's listener wrapper) if dismissal
+ // rejects the stored callback pair instead of resolving it
+ await pending
+
+ await expectLogic(logic).toMatchValues({ showAuthenticationModal: false })
+ })
})
})
diff --git a/frontend/src/lib/components/TimeSensitiveAuthentication/timeSensitiveAuthenticationLogic.ts b/frontend/src/lib/components/TimeSensitiveAuthentication/timeSensitiveAuthenticationLogic.ts
index 97417baef66d..637e9a6a5dfa 100644
--- a/frontend/src/lib/components/TimeSensitiveAuthentication/timeSensitiveAuthenticationLogic.ts
+++ b/frontend/src/lib/components/TimeSensitiveAuthentication/timeSensitiveAuthenticationLogic.ts
@@ -209,7 +209,7 @@ export const timeSensitiveAuthenticationLogic = kea<timeSensitiveAuthenticationL
listeners(({ actions, values }) => ({
submitReauthenticationSuccess: () => {
if (Array.isArray(values.timeSensitiveAuthenticationRequired)) {
- values.timeSensitiveAuthenticationRequired[0]() // Resolve
+ values.timeSensitiveAuthenticationRequired[0]() // Signal success
}
posthog.capture('reauthentication_completed')
actions.setTimeSensitiveAuthenticationRequired(false)
@@ -218,7 +218,7 @@ export const timeSensitiveAuthenticationLogic = kea<timeSensitiveAuthenticationL
},
beginPasskey2FASuccess: () => {
if (Array.isArray(values.timeSensitiveAuthenticationRequired)) {
- values.timeSensitiveAuthenticationRequired[0]() // Resolve
+ values.timeSensitiveAuthenticationRequired[0]() // Signal success
}
posthog.capture('reauthentication_completed', { method: 'passkey_2fa' })
actions.setTimeSensitiveAuthenticationRequired(false)
@@ -227,13 +227,13 @@ export const timeSensitiveAuthenticationLogic = kea<timeSensitiveAuthenticationL
},
submitReauthenticationFailure: () => {
if (Array.isArray(values.timeSensitiveAuthenticationRequired)) {
- values.timeSensitiveAuthenticationRequired[1]() // Reject
+ values.timeSensitiveAuthenticationRequired[1]() // Signal failure/dismissal
}
},
setDismissedReauthentication: ({ value }) => {
if (value) {
if (Array.isArray(values.timeSensitiveAuthenticationRequired)) {
- values.timeSensitiveAuthenticationRequired[1]() // Reject
+ values.timeSensitiveAuthenticationRequired[1]() // Signal failure/dismissal
}
posthog.capture('reauthentication_modal_dismissed')
}
@@ -243,9 +243,12 @@ export const timeSensitiveAuthenticationLogic = kea<timeSensitiveAuthenticationL
// Here we try to offer a better UX by forcing re-authentication if they are about to timeout
// which is nicer than when they try to do something later and get a 403.
// We also make this a promise, so that `checkReauthentication` callsites can await
- // `asyncActions.checkReauthentication()` and proceed once re-authentication is completed
- return new Promise((resolve, reject) =>
- actions.setTimeSensitiveAuthenticationRequired([resolve, reject])
+ // `asyncActions.checkReauthentication()` and proceed once the flow concludes.
+ // Dismissal/failure resolves rather than rejects: the mount-time dispatch is
+ // fire-and-forget, so a rejection (especially a bare `reject()`) surfaces as an
+ // unhandled TypeError in kea's listener wrapper.
+ return new Promise<void>((resolve) =>
+ actions.setTimeSensitiveAuthenticationRequired([resolve, resolve])
)
}
},
diff --git a/frontend/src/lib/logic/apiStatusLogic.ts b/frontend/src/lib/logic/apiStatusLogic.ts
index 9c276e08e3c1..2aec00c05b6e 100644
--- a/frontend/src/lib/logic/apiStatusLogic.ts
+++ b/frontend/src/lib/logic/apiStatusLogic.ts
@@ -13,7 +13,9 @@ export const apiStatusLogic = kea<apiStatusLogicType>([
actions({
onApiResponse: (response?: Response, error?: any) => ({ response, error }),
setInternetConnectionIssue: (issue: boolean) => ({ issue }),
- setTimeSensitiveAuthenticationRequired: (required: boolean | [resolve: () => void, reject: () => void]) => ({
+ setTimeSensitiveAuthenticationRequired: (
+ required: boolean | [onSuccess: () => void, onFailure: () => void]
+ ) => ({
required,
}),
setTwoFactorVerificationExpiredToastShown: (shown: boolean) => ({ shown }),
@@ -28,9 +30,10 @@ export const apiStatusLogic = kea<apiStatusLogicType>([
],
timeSensitiveAuthenticationRequired: [
- // When a tuple with resolve/reject is passed, one of these will be called
- // when re-authentication succeeds or fails/is dismissed
- false as boolean | [resolve: () => void, reject: () => void],
+ // When a tuple of callbacks is passed, one of these will be called
+ // when re-authentication succeeds or fails/is dismissed. Neither may throw
+ // or reject: the pending checkReauthentication listener awaits them fire-and-forget.
+ false as boolean | [onSuccess: () => void, onFailure: () => void],
{
setTimeSensitiveAuthenticationRequired: (_, { required }) => required,
},