38980-vm/app-9w9pd00g5j41/supabase/migrations/00020_add_provider_leads_select_policy.sql
2026-03-04 18:25:09 +00:00

17 lines
424 B
SQL

-- Add SELECT policy for providers to view available leads
-- Providers can view leads that have consent and are available (new status)
CREATE POLICY "Providers can view available leads"
ON leads
FOR SELECT
TO public
USING (
consent_given = true
AND status = 'new'
AND EXISTS (
SELECT 1
FROM profiles
WHERE profiles.id = auth.uid()
AND profiles.role = 'provider'
)
);