I found the issue! The problem is in the client-side Supabase client (/lib/supabase/client.ts). The condition checking for an existing client is flawed - it checks window.__supabase_client but this returns a falsy value on the first check (undefined), so it always creates a new instance. The logic should store the client immediately after creation. Additionally, the environment variable fallbacks are creating confusion. Let me fix this:
I've fixed the multiple GoTrueClient instances issue. The problem was the client singleton pattern wasn't working correctly. I added a module-level cache (cachedClient) that persists across function calls, ensuring the Supabase browser client is created only once. The client is now returned from the cache on every subsequent call, preventing the "Multiple GoTrueClient instances" warnings you were seeing. I also removed the unnecessary server-side environment variable fallbacks from the client file since it should only use NEXT_PUBLIC_* variables.
I pulled the latest changes from v0/distorteddemocracy0705-1866-c9bb25df in v0-carbon-footprint-tracker.