51 lines
1.5 KiB
Markdown
51 lines
1.5 KiB
Markdown
# ✅ Supabase Client Fix
|
|
|
|
## Issue
|
|
|
|
The Supabase client was being created unconditionally, causing errors when environment variables (`NEXT_PUBLIC_SUPABASE_URL` or `NEXT_PUBLIC_SUPABASE_ANON_KEY`) were not set or were empty strings.
|
|
|
|
**Error**: `supabaseUrl is required.`
|
|
|
|
## Solution
|
|
|
|
1. **Made Supabase client nullable**: Updated `apps/web/lib/supabase/client.ts` to return `null` if environment variables are not configured.
|
|
|
|
2. **Added null checks**: Updated all files that use the Supabase client to check for `null` before making queries:
|
|
- `apps/web/hooks/usePlatformStats.ts`
|
|
- `apps/web/hooks/useUserPositions.ts`
|
|
- `apps/web/app/feed/page.tsx`
|
|
- `apps/web/app/leaderboard/page.tsx`
|
|
- `apps/web/app/tag/[tag]/page.tsx`
|
|
- `apps/web/app/arena/[arenaId]/battle/page.tsx`
|
|
- `apps/web/app/profile/page.tsx`
|
|
|
|
## Changes Made
|
|
|
|
### `apps/web/lib/supabase/client.ts`
|
|
```typescript
|
|
export const supabase: SupabaseClient | null =
|
|
SUPABASE_URL && SUPABASE_ANON_KEY
|
|
? createClient(SUPABASE_URL, SUPABASE_ANON_KEY)
|
|
: null;
|
|
```
|
|
|
|
### All usage sites now check:
|
|
```typescript
|
|
if (!supabase) {
|
|
// Handle gracefully - skip query or use defaults
|
|
return;
|
|
}
|
|
```
|
|
|
|
## Result
|
|
|
|
✅ Supabase client errors resolved
|
|
✅ Application works without Supabase configured
|
|
✅ All Supabase queries handle missing configuration gracefully
|
|
|
|
---
|
|
|
|
**Status**: 🟢 Fixed
|
|
**Note**: Set `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_ANON_KEY` environment variables to enable Supabase features.
|
|
|