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(ui): recover remote-auth expiry globally in apiFetch

cyh61d2928973b8
diff --git a/ui/src/lib/apiFetch.ts b/ui/src/lib/apiFetch.ts
index 33e9ac8e2..d213293cb 100644
--- a/ui/src/lib/apiFetch.ts
+++ b/ui/src/lib/apiFetch.ts
@@ -66,5 +66,39 @@ export async function apiFetch(input: RequestInfo | URL, init: RequestInit = {})
}
nextInit.headers = headers;
- return fetch(input, nextInit);
+ const response = await fetch(input, nextInit);
+ // Global remote-access auth recovery. The AuthGuard validates the session
+ // once and then stops re-running on ordinary navigation (so it doesn't
+ // re-mount the shell on every sidebar click). If the Avibe Cloud cookie
+ // expires after that, no component re-checks auth — but the server starts
+ // answering /api/* with 401 `remote_access_login_required`. Detect it here
+ // and trigger the same full-page login redirect the guard uses, so the user
+ // lands on the login flow instead of a wall of silently-failing fetches.
+ if (response.status === 401) {
+ void maybeRedirectOnRemoteAuthExpiry(response.clone());
+ }
+ return response;
+}
+
+let redirectingForRemoteAuth = false;
+
+async function maybeRedirectOnRemoteAuthExpiry(response: Response): Promise<void> {
+ if (redirectingForRemoteAuth || typeof window === 'undefined') {
+ return;
+ }
+ let payload: unknown;
+ try {
+ payload = await response.json();
+ } catch {
+ // Non-JSON 401 — not the remote-access signal; let the caller handle it.
+ return;
+ }
+ if ((payload as { error?: string } | null)?.error !== 'remote_access_login_required') {
+ return;
+ }
+ redirectingForRemoteAuth = true;
+ // Full-page navigation to the current path: enforce_remote_access_cookie
+ // redirects an unauthenticated browser request to the Avibe Cloud login
+ // (mirrors RemoteLoginRedirect in App.tsx).
+ window.location.assign(window.location.href);
}