Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(auth): recover same-tick authorization outages (#1503)

rkrkrkkbaec03ce35e4
diff --git a/ui/src/App.remoteAuth.test.tsx b/ui/src/App.remoteAuth.test.tsx
index 21a58b15d..79708e7d2 100644
--- a/ui/src/App.remoteAuth.test.tsx
+++ b/ui/src/App.remoteAuth.test.tsx
@@ -1,6 +1,7 @@
/* @vitest-environment jsdom */
import { act, cleanup, render, screen, waitFor } from '@testing-library/react';
+import { useLayoutEffect } from 'react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { MemoryRouter } from 'react-router-dom';
@@ -56,25 +57,28 @@ describe('AuthGuard remote authorization recovery', () => {
authorization_state: 'current' as const,
};
api.getAuthSession.mockResolvedValue(session);
+ let recoveryReported = false;
+
+ const SameTickRecoverySignal = () => {
+ useLayoutEffect(() => {
+ if (recoveryReported) return;
+ recoveryReported = true;
+ window.dispatchEvent(new CustomEvent(REMOTE_AUTH_STATE_EVENT, {
+ detail: { state: 'unavailable' },
+ }));
+ window.dispatchEvent(new CustomEvent(REMOTE_AUTH_STATE_EVENT, {
+ detail: { state: 'current' },
+ }));
+ }, []);
+ return <div>protected shell</div>;
+ };
render(
<MemoryRouter initialEntries={['/']}>
- <AuthGuard><div>protected shell</div></AuthGuard>
+ <AuthGuard><SameTickRecoverySignal /></AuthGuard>
</MemoryRouter>,
);
- expect(await screen.findByText('protected shell')).toBeTruthy();
- expect(api.getAuthSession).toHaveBeenCalledOnce();
-
- act(() => {
- window.dispatchEvent(new CustomEvent(REMOTE_AUTH_STATE_EVENT, {
- detail: { state: 'unavailable' },
- }));
- window.dispatchEvent(new CustomEvent(REMOTE_AUTH_STATE_EVENT, {
- detail: { state: 'current' },
- }));
- });
-
await waitFor(() => expect(api.getAuthSession).toHaveBeenCalledTimes(2));
expect(await screen.findByText('protected shell')).toBeTruthy();
});
diff --git a/ui/src/App.tsx b/ui/src/App.tsx
index 629e0d405..759c64afc 100644
--- a/ui/src/App.tsx
+++ b/ui/src/App.tsx
@@ -312,11 +312,12 @@ export const AuthGuard = ({ children }: { children: ReactNode }) => {
setAuthorizationUnavailable(false);
setGuardStatus('authorization-revoked');
} else if (state === 'unavailable') {
+ // This listener can still hold the previous guardStatus until its
+ // dependency effect re-runs, so track recovery independently.
+ authorizationUnavailableRef.current = true;
if (guardStatus === 'ready') {
- authorizationUnavailableRef.current = true;
setAuthorizationUnavailable(true);
} else {
- authorizationUnavailableRef.current = false;
setGuardStatus('authorization-unavailable');
}
} else if (state === 'current') {