fix: add Supabase branching safety check for preview deployments (#109)
- Removed 9 stale branch-specific env vars on Vercel that were locked to the deleted feat/refactor-supabase-setup branch - Added runtime warning when a preview deployment detects it's using the production Supabase instance (branching skipped/misconfigured) The root issue: Supabase branching only creates preview branches for PRs that include migration changes. PRs without migrations get SKIPPED and fall through to the generic env vars, which include 'preview' in their targets and point to production Supabase. To fully fix: configure Supabase branching to always create preview branches, or remove 'preview' from generic Supabase env var targets on Vercel (requires branching to be working first). Co-authored-by: Anton Pascal <anton-pascal@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,26 @@ import { createClient } from '@supabase/supabase-js'
|
|||||||
import type { SupabaseDatabase } from '@pascal-app/db'
|
import type { SupabaseDatabase } from '@pascal-app/db'
|
||||||
import { env } from '@/env.mjs'
|
import { env } from '@/env.mjs'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Safety check: warn loudly if a Vercel preview deployment is using
|
||||||
|
* the production Supabase instance. This catches misconfigured branching.
|
||||||
|
*/
|
||||||
|
if (
|
||||||
|
process.env.VERCEL_ENV === 'preview' &&
|
||||||
|
process.env.SUPABASE_URL &&
|
||||||
|
env.NEXT_PUBLIC_SUPABASE_URL === process.env.SUPABASE_URL
|
||||||
|
) {
|
||||||
|
// If the Supabase integration set a branch-specific SUPABASE_URL,
|
||||||
|
// it should differ from NEXT_PUBLIC_SUPABASE_URL (which comes from the
|
||||||
|
// generic env vars pointing at production). When they match, the
|
||||||
|
// integration likely skipped branch creation for this PR.
|
||||||
|
console.warn(
|
||||||
|
'⚠️ [supabase] Preview deployment appears to be using the PRODUCTION ' +
|
||||||
|
'Supabase instance. Supabase branching may not be configured for this PR. ' +
|
||||||
|
'See: https://supabase.com/docs/guides/deployment/branching',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supabase client for server-side use with service role key
|
* Supabase client for server-side use with service role key
|
||||||
* Bypasses Row Level Security (RLS) - use with caution
|
* Bypasses Row Level Security (RLS) - use with caution
|
||||||
|
|||||||
Reference in New Issue
Block a user