Skip to content

Commit a734a12

Browse files
committed
fix(shared): preserve device decision lock across reset
1 parent aa68708 commit a734a12

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

packages/shared/src/react/hooks/__tests__/useOAuthDeviceVerification.spec.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,25 @@ describe('useOAuthDeviceVerification', () => {
230230
expect(result.current.result).toBeUndefined();
231231
expect(result.current.error).toBeNull();
232232
});
233+
234+
it('reset keeps a pending decision locked until its request settles', async () => {
235+
let resolveSubmit!: (value: OAuthDeviceVerificationResult) => void;
236+
submitDeviceVerification.mockImplementationOnce(() => new Promise(resolve => (resolveSubmit = resolve)));
237+
const { result } = renderHook(() => useOAuthDeviceVerification(), { wrapper });
238+
239+
let first!: Promise<OAuthDeviceVerificationResult>;
240+
act(() => {
241+
first = result.current.approve({ userCode: 'BCDF-GHJK' });
242+
});
243+
act(() => result.current.reset());
244+
245+
const second = result.current.deny({ userCode: 'BCDF-GHJK' });
246+
await expect(second).rejects.toMatchObject({ code: 'oauth_device_verification_submission_in_progress' });
247+
expect(submitDeviceVerification).toHaveBeenCalledOnce();
248+
249+
resolveSubmit(approvedResult);
250+
await act(() => first);
251+
await act(() => result.current.deny({ userCode: 'BCDF-GHJK' }));
252+
expect(submitDeviceVerification).toHaveBeenCalledTimes(2);
253+
});
233254
});

packages/shared/src/react/hooks/useOAuthDeviceVerification.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ export function useOAuthDeviceVerification(): UseOAuthDeviceVerificationReturn {
187187
const reset = useCallback(() => {
188188
generation.current += 1;
189189
pendingLookup.current = null;
190-
pendingSubmit.current = null;
191190
setData(undefined);
192191
setResult(undefined);
193192
setError(null);

0 commit comments

Comments
 (0)