Merge pull request #7732 from ouchihao/codex/bug-step-up-concurrent-prompts

fix(auth): share pending step-up verification prompts
This commit is contained in:
Wesley Liddick authored and GitHub committed 2026-10-08 13:48:52 +08:00
commit 9e46f2d77e
2 files changed
+27 -1

No files matched your search

@@ -28,6 +28,27 @@ describe('useStepUp error classification', () => {
})
})
describe('useStepUp concurrent prompts', () => {
it.each([true, false])('settles every waiter when verification resolves to %s', async (verified) => {
const stepUp = useStepUp()
const firstDone = vi.fn()
const secondDone = vi.fn()
const first = stepUp.prompt()
first.then(firstDone)
stepUp.prompt().then(secondDone)
if (verified) stepUp.onVerified()
else stepUp.onCancel()
await Promise.resolve()
expect(firstDone).toHaveBeenCalledWith(verified)
expect(secondDone).toHaveBeenCalledWith(verified)
expect(stepUp.visible.value).toBe(false)
const next = stepUp.prompt()
expect(next).not.toBe(first)
stepUp.onCancel()
await expect(next).resolves.toBe(false)
})
})
describe('useStepUp.run', () => {
it('returns the action result directly on success', async () => {
const stepUp = useStepUp()
+6 -1
View File
@@ -68,25 +68,30 @@ export function useStepUp() {
const visible = ref(false)
const blockedReason = ref<string>('')
let resolver: ((ok: boolean) => void) | null = null
let pendingPrompt: Promise<boolean> | null = null
/** Open the TOTP dialog and resolve true once a grant is obtained. */
function prompt(): Promise<boolean> {
if (pendingPrompt) return pendingPrompt
visible.value = true
return new Promise<boolean>((resolve) => {
pendingPrompt = new Promise<boolean>((resolve) => {
resolver = resolve
})
return pendingPrompt
}
function onVerified() {
visible.value = false
resolver?.(true)
resolver = null
pendingPrompt = null
}
function onCancel() {
visible.value = false
resolver?.(false)
resolver = null
pendingPrompt = null
}
/**