Skip to content

[Bug] supabaseAdmin typed as any allowing silent null crashes across all API routes #1249

@akhilmodi29

Description

@akhilmodi29

Bug Description

supabaseAdmin in src/lib/supabase.ts is typed as any despite
being explicitly set to null when environment variables are missing.
This means TypeScript provides zero protection — any API route calling
supabaseAdmin.from(...) without a null check will throw an unhandled
TypeError: Cannot read properties of null at runtime, crashing the
entire route handler.

Steps to Reproduce

  1. Remove or leave empty NEXT_PUBLIC_SUPABASE_URL in .env.local
  2. Hit any API route that uses supabaseAdmin directly
  3. Observe: unhandled TypeError crashes the route instead of a
    clean error response

Expected Behavior

TypeScript should catch unguarded supabaseAdmin calls at compile
time. The type should reflect that it can be null so developers
are forced to handle that case.

Root Cause

In src/lib/supabase.ts:

export const supabaseAdmin: any = ...

Typing it as any disables all TypeScript checks. The correct type
is SupabaseClient | null which forces null checks at every call site.

Fix

Import SupabaseClient and use it as the type:

import { createClient, SupabaseClient } from "@supabase/supabase-js";

export const supabaseAdmin: SupabaseClient | null =
  supabaseUrl && serviceRoleKey && !supabaseUrl.includes("placeholder")
    ? createClient(supabaseUrl, serviceRoleKey)
    : null;

File Affected

src/lib/supabase.ts

Impact

Every API route in the app that uses supabaseAdmin is affected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageNeeds maintainer triage

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions