fix(mobile): ignore duplicate add-account close requests

Signed-off-by: chenhong <alusa@xd.com>
This commit is contained in:
chenhong
2026-10-09 17:42:10 +08:00
parent ddaf468dfd
commit 7c2160ee45
2 changed files with 24 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ export default function AddAccountScreen() {
<LoginScreen
additionalAccount
onClose={() => {
if (closeStartedRef.current) return;
closeStartedRef.current = true;
void auth.cancelAddAccount().then(
() => router.replace('/devices'),

View File

@@ -292,6 +292,29 @@ describe('browser auth session lifecycle (real AuthProvider, mocked native/netwo
expect(native.storage.has(pendingKey)).toBe(false);
});
it('ignores repeated close taps while cancellation is pending, including storage failure', async () => {
await act(async () => { await auth.beginAddAccount(); });
await start();
const pending = native.storage.get(pendingKey);
const url = callbackUrl();
await act(async () => { root.render(<AuthProvider><Probe /><AddAccountScreen /></AuthProvider>); });
native.writeSecure.mockRejectedValue(new Error('fixture storage unavailable'));
native.deleteSecure.mockRejectedValue(new Error('fixture storage unavailable'));
const writes = native.writeSecure.mock.calls.length;
await act(async () => { native.closeAccount!(); native.closeAccount!(); });
expect(native.replaceRoute).not.toHaveBeenCalled();
expect(native.writeSecure.mock.calls.length - writes).toBe(1);
expect(auth.loginState?.step).toBe('error');
expect(native.storage.get(pendingKey)).toBe(pending);
await emitLink(url);
expect(native.exchange).not.toHaveBeenCalled();
native.writeSecure.mockImplementation(async (key: string, value: string) => { native.storage.set(key, value); });
native.deleteSecure.mockImplementation(async (key: string) => { native.storage.delete(key); });
await act(async () => { native.closeAccount!(); });
expect(native.replaceRoute).toHaveBeenCalledExactlyOnceWith('/devices');
expect(native.storage.has(pendingKey)).toBe(false);
});
it('surfaces a failed unmount cancellation without an unhandled rejection', async () => {
await act(async () => { await auth.beginAddAccount(); });
await start();