mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 08:05:12 +00:00
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:
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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user