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
- Remove or leave empty
NEXT_PUBLIC_SUPABASE_URL in .env.local
- Hit any API route that uses
supabaseAdmin directly
- 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.
Bug Description
supabaseAdmininsrc/lib/supabase.tsis typed asanydespitebeing explicitly set to
nullwhen environment variables are missing.This means TypeScript provides zero protection — any API route calling
supabaseAdmin.from(...)without a null check will throw an unhandledTypeError: Cannot read properties of nullat runtime, crashing theentire route handler.
Steps to Reproduce
NEXT_PUBLIC_SUPABASE_URLin.env.localsupabaseAdmindirectlyTypeErrorcrashes the route instead of aclean error response
Expected Behavior
TypeScript should catch unguarded
supabaseAdmincalls at compiletime. The type should reflect that it can be
nullso developersare forced to handle that case.
Root Cause
In
src/lib/supabase.ts:Typing it as
anydisables all TypeScript checks. The correct typeis
SupabaseClient | nullwhich forces null checks at every call site.Fix
Import
SupabaseClientand use it as the type:File Affected
src/lib/supabase.tsImpact
Every API route in the app that uses
supabaseAdminis affected.