# Combine Algolia Search Results with Supabase User Favorites

> To combine algolia search results with supabase user favorites, configure parallel steps for Supabase and Algolia. Frontend / Web performs one authorized GET/POST to RealComposer and receives a merged payload.

- Canonical page: https://realcomposer.com/recipes/combine-algolia-search-with-user-favorites
- Client platform: Frontend / Web
- Upstream services: Supabase, Algolia
- Category: Multi-API Aggregation
- JSON version: https://realcomposer.com/recipes/combine-algolia-search-with-user-favorites.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=combine-algolia-search-with-user-favorites&via=agent

## Problem: Serial Supabase and Algolia calls slow Frontend / Web pages

Each extra Supabase and Algolia hop adds hundreds of milliseconds and another OAuth refresh path your UI must manage.

- One slow upstream blocking an entire page
- Partial failures leaving UI in inconsistent states
- Duplicate auth refresh logic per service

## Solution steps

1. **Store upstream credentials in Secret Vault**: Add SUPABASE_SERVICE_ROLE_KEY, ALGOLIA_API_KEY to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2. **Target the real upstream URL**: Use POST against https://{{secrets.SUPABASE_PROJECT_REF}}.supabase.co/rest/v1/{{query.table}}?{{query.filter}}. Allowed origins on the client token should match post pipelines set cache ttl to 0 because realcomposer only stores get responses at the edge.

3. **Call from Frontend / Web**: Allowed origins on the token should list every Frontend / Web host that calls this URL.

```
const res = await fetch('https://realcomposer.com/v1/workspace/combine-algolia-search-with-user-favorites', {
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
```

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "Combine Algolia Search Results with Supabase User Favorites",
  "method": "POST",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "supabase",
      "upstreamUrlTemplate": "https://{{secrets.SUPABASE_PROJECT_REF}}.supabase.co/rest/v1/{{query.table}}?{{query.filter}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "apikey": "{{secrets.SUPABASE_SERVICE_ROLE_KEY}}",
        "Authorization": "Bearer {{secrets.SUPABASE_SERVICE_ROLE_KEY}}"
      },
      "timeoutMs": 3000
    },
    {
      "stepKey": "algolia",
      "upstreamUrlTemplate": "https://{{secrets.ALGOLIA_APP_ID}}-dsn.algolia.net/1/indexes/{{query.index}}/query",
      "httpMethod": "POST",
      "headersTemplate": {
        "X-Algolia-API-Key": "{{secrets.ALGOLIA_API_KEY}}",
        "X-Algolia-Application-Id": "{{secrets.ALGOLIA_APP_ID}}",
        "Content-Type": "application/json"
      },
      "timeoutMs": 10000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "supabase.rowId",
        "sourcePath": "0.id",
        "type": "string",
        "sourceStep": "supabase"
      },
      {
        "targetPath": "supabase.email",
        "sourcePath": "0.email",
        "type": "string",
        "sourceStep": "supabase"
      },
      {
        "targetPath": "algolia.hitCount",
        "sourcePath": "nbHits",
        "type": "number",
        "sourceStep": "algolia"
      },
      {
        "targetPath": "algolia.firstHit",
        "sourcePath": "hits.0.objectID",
        "type": "string",
        "sourceStep": "algolia"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X POST "https://realcomposer.com/v1/workspace/combine-algolia-search-with-user-favorites" \
  -H "Authorization: Bearer rc_live_client_token" \
  -H "Content-Type: application/json" \
  -d '{"model":"example"}'
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_combine-",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "combine-algolia-search-with-user-favorites"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "supabase_rowId": "sample",
  "supabase_email": "sample",
  "algolia_hitCount": "sample",
  "algolia_firstHit": "sample"
}
```

## FAQ

### Can Frontend / Web call Supabase without holding the production key?

Point Frontend / Web at /recipes/combine-algolia-search-with-user-favorites edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins.

### Does POST traffic get cached?

combine-algolia-search-with-user-favorites POST steps bypass caches.default even if cacheTtlSeconds is set in the dashboard.

### What happens if an upstream step times out?

Upstream steps in combine-algolia-search-with-user-favorites honor timeoutMs and optional fallback JSON without leaking secrets.
