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 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; -}