From a8cf33aed76ade67f956e6b2b06da96dde7bfb0a Mon Sep 17 00:00:00 2001 From: mahaprasad nanda Date: Fri, 19 Jun 2026 22:17:01 +0530 Subject: [PATCH 1/2] Remove unused Supabase request auth helper --- backend/src/lib/supabase.ts | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/backend/src/lib/supabase.ts b/backend/src/lib/supabase.ts index da821862..51ad41ed 100644 --- a/backend/src/lib/supabase.ts +++ b/backend/src/lib/supabase.ts @@ -12,33 +12,3 @@ export function createServerSupabase() { } return createClient(url, key, { auth: { persistSession: false } }); } - -/** - * Extract and verify the Supabase JWT from the Authorization header. - * Returns the user's UUID string, or throws a Response with 401. - */ -export async function getUserIdFromRequest(req: Request): Promise { - const auth = req.headers.get("authorization") ?? ""; - if (!auth.startsWith("Bearer ")) { - throw new Response("Missing or invalid Authorization header", { - status: 401, - }); - } - const token = auth.slice(7).trim(); - - const supabaseUrl = process.env.SUPABASE_URL || ""; - const serviceKey = process.env.SUPABASE_SECRET_KEY || ""; - - if (!supabaseUrl || !serviceKey) { - throw new Response("Server auth is not configured", { status: 500 }); - } - - const admin = createClient(supabaseUrl, serviceKey, { - auth: { persistSession: false }, - }); - const { data } = await admin.auth.getUser(token); - if (!data.user) { - throw new Response("Invalid or expired token", { status: 401 }); - } - return data.user.id; -} From 80d14b86fcd42351807fe8a3d672ff99926b2f8e Mon Sep 17 00:00:00 2001 From: willchen96 Date: Sun, 26 Jul 2026 01:39:42 +0800 Subject: [PATCH 2/2] test: drop mocks of removed getUserIdFromRequest helper The integration tests landed on main after this branch was cut and mocked the helper this PR deletes. Vitest factory mocks don't validate against the real module shape, so the extra key was harmless but misleading. Co-Authored-By: Claude Fable 5 --- backend/src/__tests__/integration/chat.routes.test.ts | 1 - backend/src/__tests__/integration/documentsUpload.routes.test.ts | 1 - backend/src/__tests__/integration/projectChat.routes.test.ts | 1 - backend/src/__tests__/integration/projects.routes.test.ts | 1 - backend/src/__tests__/integration/tabular.routes.test.ts | 1 - backend/src/__tests__/integration/user.routes.test.ts | 1 - 6 files changed, 6 deletions(-) diff --git a/backend/src/__tests__/integration/chat.routes.test.ts b/backend/src/__tests__/integration/chat.routes.test.ts index 64e71ecd..8f967663 100644 --- a/backend/src/__tests__/integration/chat.routes.test.ts +++ b/backend/src/__tests__/integration/chat.routes.test.ts @@ -41,7 +41,6 @@ function mockSupabase() { vi.mock("../../lib/supabase", () => ({ createServerSupabase: vi.fn(() => mockSupabase()), - getUserIdFromRequest: vi.fn(async () => "u1"), })); // Authenticate every request as user "u1" without exercising the real Supabase diff --git a/backend/src/__tests__/integration/documentsUpload.routes.test.ts b/backend/src/__tests__/integration/documentsUpload.routes.test.ts index e7544cfb..faca4ab0 100644 --- a/backend/src/__tests__/integration/documentsUpload.routes.test.ts +++ b/backend/src/__tests__/integration/documentsUpload.routes.test.ts @@ -25,7 +25,6 @@ function mockSupabase() { vi.mock("../../lib/supabase", () => ({ createServerSupabase: vi.fn(() => mockSupabase()), - getUserIdFromRequest: vi.fn(async () => "u1"), })); vi.mock("../../middleware/auth", () => ({ diff --git a/backend/src/__tests__/integration/projectChat.routes.test.ts b/backend/src/__tests__/integration/projectChat.routes.test.ts index 8f6af783..e2fbd5e3 100644 --- a/backend/src/__tests__/integration/projectChat.routes.test.ts +++ b/backend/src/__tests__/integration/projectChat.routes.test.ts @@ -38,7 +38,6 @@ function mockSupabase() { vi.mock("../../lib/supabase", () => ({ createServerSupabase: vi.fn(() => mockSupabase()), - getUserIdFromRequest: vi.fn(async () => "u1"), })); vi.mock("../../middleware/auth", () => ({ diff --git a/backend/src/__tests__/integration/projects.routes.test.ts b/backend/src/__tests__/integration/projects.routes.test.ts index 408f24e2..d54eead2 100644 --- a/backend/src/__tests__/integration/projects.routes.test.ts +++ b/backend/src/__tests__/integration/projects.routes.test.ts @@ -68,7 +68,6 @@ function mockSupabase() { vi.mock("../../lib/supabase", () => ({ createServerSupabase: vi.fn(() => mockSupabase()), - getUserIdFromRequest: vi.fn(async () => "u1"), })); vi.mock("../../middleware/auth", () => ({ diff --git a/backend/src/__tests__/integration/tabular.routes.test.ts b/backend/src/__tests__/integration/tabular.routes.test.ts index c828148c..6ee9db10 100644 --- a/backend/src/__tests__/integration/tabular.routes.test.ts +++ b/backend/src/__tests__/integration/tabular.routes.test.ts @@ -81,7 +81,6 @@ function mockSupabase() { vi.mock("../../lib/supabase", () => ({ createServerSupabase: vi.fn(() => mockSupabase()), - getUserIdFromRequest: vi.fn(async () => "u1"), })); vi.mock("../../middleware/auth", () => ({ diff --git a/backend/src/__tests__/integration/user.routes.test.ts b/backend/src/__tests__/integration/user.routes.test.ts index d47b5bb5..2e043297 100644 --- a/backend/src/__tests__/integration/user.routes.test.ts +++ b/backend/src/__tests__/integration/user.routes.test.ts @@ -106,7 +106,6 @@ function mockSupabase() { vi.mock("../../lib/supabase", () => ({ createServerSupabase: vi.fn(() => mockSupabase()), - getUserIdFromRequest: vi.fn(async () => "u1"), })); // requireAuth always authenticates u1. requireMfaIfEnrolled is a reconfigurable