# send-push-notification

Edge Function que envia push notifications via Firebase Cloud Messaging (FCM) quando uma notificação é inserida na tabela `notifications`.

## Setup (1x por projeto)

### 1. Configurar secrets no Supabase

```bash
supabase secrets set FIREBASE_PROJECT_ID=your-firebase-project-id
supabase secrets set FIREBASE_SERVICE_ACCOUNT_JSON='{"type":"service_account","project_id":"..."}'
```

O JSON do service account: Firebase Console → Project Settings → Service Accounts → **Generate new private key**.

### 2. Deploy da Edge Function

```bash
supabase functions deploy send-push-notification --project-ref YOUR_PROJECT_REF
```

### 3. Configurar Database Webhook

No Supabase Dashboard → **Database → Webhooks → Create webhook**:

| Campo | Valor |
|-------|-------|
| Name | `on_notification_inserted` |
| Table | `notifications` |
| Events | `INSERT` |
| Method | POST |
| URL | `https://YOUR_PROJECT_REF.supabase.co/functions/v1/send-push-notification` |
| Headers | `Authorization: Bearer YOUR_SUPABASE_ANON_KEY` |

Sem este webhook, a edge function não é chamada automaticamente.
