Merge pull request #186 from user-in-search-of-a-name/codex/remove-dead-supabase-auth-helper

[codex] Remove unused Supabase request auth helper
This commit is contained in:
Will Chen 2026-07-26 01:49:53 +08:00 committed by GitHub
commit 416b32b17f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 0 additions and 36 deletions

View file

@ -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

View file

@ -25,7 +25,6 @@ function mockSupabase() {
vi.mock("../../lib/supabase", () => ({
createServerSupabase: vi.fn(() => mockSupabase()),
getUserIdFromRequest: vi.fn(async () => "u1"),
}));
vi.mock("../../middleware/auth", () => ({

View file

@ -38,7 +38,6 @@ function mockSupabase() {
vi.mock("../../lib/supabase", () => ({
createServerSupabase: vi.fn(() => mockSupabase()),
getUserIdFromRequest: vi.fn(async () => "u1"),
}));
vi.mock("../../middleware/auth", () => ({

View file

@ -68,7 +68,6 @@ function mockSupabase() {
vi.mock("../../lib/supabase", () => ({
createServerSupabase: vi.fn(() => mockSupabase()),
getUserIdFromRequest: vi.fn(async () => "u1"),
}));
vi.mock("../../middleware/auth", () => ({

View file

@ -81,7 +81,6 @@ function mockSupabase() {
vi.mock("../../lib/supabase", () => ({
createServerSupabase: vi.fn(() => mockSupabase()),
getUserIdFromRequest: vi.fn(async () => "u1"),
}));
vi.mock("../../middleware/auth", () => ({

View file

@ -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

View file

@ -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<string> {
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;
}