Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(auth): keep forbidden responses from expiring sessions

Louis Beaumontc5f4537953a7
diff --git a/apps/screenpipe-app-tauri/lib/auth-guard.test.tsx b/apps/screenpipe-app-tauri/lib/auth-guard.test.tsx
index dc72982dc..936641966 100644
--- a/apps/screenpipe-app-tauri/lib/auth-guard.test.tsx
+++ b/apps/screenpipe-app-tauri/lib/auth-guard.test.tsx
@@ -250,17 +250,16 @@ describe("AuthGuard session-expiry handling", () => {
);
});
- it("clears the full account when a focus re-verify returns 403", async () => {
+ it("keeps the session when a focus re-verify returns 403", async () => {
mocks.loadUser.mockRejectedValueOnce(
new Error("failed to verify token: 403 Forbidden")
);
renderGuard();
fireEvent(window, new Event("focus"));
- await waitFor(() => expect(mocks.updateSettings).toHaveBeenCalled());
- const arg = mocks.updateSettings.mock.calls[0][0];
- expect(arg.user).toBeNull();
- expect(mocks.setCloudToken).toHaveBeenCalledWith(null);
+ await waitFor(() => expect(mocks.loadUser).toHaveBeenCalled());
+ expect(mocks.updateSettings).not.toHaveBeenCalled();
+ expect(mocks.setCloudToken).not.toHaveBeenCalled();
});
it("keeps the session on a transient network / 5xx error", async () => {
@@ -269,7 +268,7 @@ describe("AuthGuard session-expiry handling", () => {
fireEvent(window, new Event("focus"));
await waitFor(() => expect(mocks.loadUser).toHaveBeenCalled());
- // a network blip must NOT clear the session — only 401/403 do
+ // a network blip must NOT clear the session — only a verified 401 does
expect(mocks.updateSettings).not.toHaveBeenCalled();
expect(mocks.setCloudToken).not.toHaveBeenCalled();
});
@@ -316,6 +315,13 @@ describe("installAuthInterceptor sign-out scoping", () => {
);
});
+ it("does NOT sign out on a 403 from the website auth surface", async () => {
+ originalFetch.mockResolvedValue({ status: 403 });
+ await (window as any).fetch("https://screenpipe.com/api/composio/authorize");
+ expect(clearSession).not.toHaveBeenCalled();
+ expect(mocks.capture).not.toHaveBeenCalled();
+ });
+
it("ignores a 200 from the auth surface", async () => {
originalFetch.mockResolvedValue({ status: 200 });
await (window as any).fetch("https://screenpipe.com/api/user");
diff --git a/apps/screenpipe-app-tauri/lib/auth-guard.tsx b/apps/screenpipe-app-tauri/lib/auth-guard.tsx
index b44953368..bc42a2a10 100644
--- a/apps/screenpipe-app-tauri/lib/auth-guard.tsx
+++ b/apps/screenpipe-app-tauri/lib/auth-guard.tsx
@@ -114,7 +114,7 @@ export function isScreenpipeApi(url: string): boolean {
);
}
-// The subset of screenpipe cloud hosts whose 401/403 genuinely means the login
+// The subset of screenpipe cloud hosts whose 401 genuinely means the login
// SESSION died — the website auth surface (screenpipe.com/api/user and the
// OAuth/session endpoints). This is what the fetch interceptor keys its
// sign-out on.
@@ -149,7 +149,7 @@ export function AuthGuard({ children }: { children: React.ReactNode }) {
source: context?.source ?? "verify_token",
status: context?.status ?? null,
});
- // A verified 401/403 is not a hydration failure. Clear the entire account
+ // A verified 401 is not a hydration failure. Clear the entire account
// so the persisted id cannot masquerade as an indefinitely pending token.
await updateSettings({ user: null as any });
try {
@@ -176,13 +176,14 @@ export function AuthGuard({ children }: { children: React.ReactNode }) {
await loadUser(token);
} catch (err) {
const msg = err instanceof Error ? err.message : "";
- // loadUser throws "failed to verify token: 401 ..." / "403 ..." for
- // auth failures; treat those as session expiry. Anything else
+ // loadUser throws "failed to verify token: 401 ..." when the session is
+ // invalid. A 403 means the session is valid but lacks permission, so it
+ // must never clear the account. Anything else
// (network blip, 5xx) is silent — retry on the next interval.
- if (msg.includes(" 401 ") || msg.includes(" 403 ")) {
+ if (msg.includes(" 401 ")) {
await handleSessionExpired({
source: "verify_token",
- status: msg.includes(" 403 ") ? 403 : 401,
+ status: 401,
});
}
}
@@ -248,7 +249,7 @@ export function installAuthInterceptor(
? input.href
: input.url;
- if (isScreenpipeAuthApi(url) && (res.status === 401 || res.status === 403)) {
+ if (isScreenpipeAuthApi(url) && res.status === 401) {
const token = getToken();
if (token) {
console.warn("auth-interceptor: 401 from", url);