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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(app): authenticate referral lookup to prevent sign-out (#6959)
Ezra Ellette1494836d8f34
diff --git a/apps/screenpipe-app-tauri/components/settings/referral-card.test.tsx b/apps/screenpipe-app-tauri/components/settings/referral-card.test.tsxindex ffd018040..9e3be680f 100644--- a/apps/screenpipe-app-tauri/components/settings/referral-card.test.tsx+++ b/apps/screenpipe-app-tauri/components/settings/referral-card.test.tsx@@ -32,6 +32,7 @@ vi.mock("@/lib/utils/tauri", () => ({vi.mock("@/components/ui/use-toast", () => ({ toast: mocks.toast }));import { ReferralCard } from "./referral-card";+import { installAuthInterceptor } from "@/lib/auth-guard";const referral = {code: "REF-A1B2C3D4",@@ -76,17 +77,23 @@ describe("ReferralCard", () => {);});- it("explains paid-plan eligibility instead of showing a broken trial link", async () => {+ it("keeps a free account signed in when it has no referral code", async () => {mocks.user = { email: "[email protected]", token: "token-1" };+ const clearSession = vi.fn(async () => {+ mocks.user = null;+ });vi.stubGlobal("fetch",- vi.fn().mockResolvedValue(- new Response(JSON.stringify({ error: "no referral code found" }), {- status: 404,- headers: { "Content-Type": "application/json" },- }),- ),+ vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {+ const authenticated =+ new Headers(init?.headers).get("Authorization") === "Bearer token-1";+ return new Response(+ JSON.stringify({ error: authenticated ? "no referral code found" : "unauthorized" }),+ { status: authenticated ? 404 : 401 },+ );+ }),);+ installAuthInterceptor(() => mocks.user?.token, clearSession);render(<ReferralCard />);@@ -94,6 +101,8 @@ describe("ReferralCard", () => {await screen.findByText(/free Business trial does not create a referral code/i),).toBeInTheDocument();expect(screen.queryByDisplayValue(/REF-/i)).not.toBeInTheDocument();+ expect(clearSession).not.toHaveBeenCalled();+ expect(mocks.user?.token).toBe("token-1");});it("shows a retry path when referral loading fails", async () => {diff --git a/apps/screenpipe-app-tauri/components/settings/referral-card.tsx b/apps/screenpipe-app-tauri/components/settings/referral-card.tsxindex 8fa6965e1..8e272b885 100644--- a/apps/screenpipe-app-tauri/components/settings/referral-card.tsx+++ b/apps/screenpipe-app-tauri/components/settings/referral-card.tsx@@ -50,7 +50,10 @@ export function ReferralCard() {`/api/referral?email=${encodeURIComponent(userEmail)}`,"https://screenpipe.com",),- { signal: controller.signal },+ {+ headers: { Authorization: `Bearer ${userToken}` },+ signal: controller.signal,+ },);if (res.status === 404) {setReferral(null);