# From their client calls to ours

What the common calls of the Supabase and Firebase client libraries become on Rezin Core. Rezin Core's API is plain HTTPS and JSON; there is no client library to install yet, so each call below is a request you can make with `fetch`.

Every request carries your project's key in `apikey`. A signed-in user's requests also carry `authorization: Bearer <token>`, the token sign-in gave you.

```
const API = 'https://api.rezincore.com';
const headers = { apikey: PUBLISHABLE_KEY, authorization: `Bearer ${token}`, 'content-type': 'application/json' };
```

## Sign-in

| Supabase | Firebase | Rezin Core |
|---|---|---|
| `auth.signUp({ email, password })` | `createUserWithEmailAndPassword` | `POST /v1/auth/signup` |
| `auth.signInWithPassword(...)` | `signInWithEmailAndPassword` | `POST /v1/auth/signin` |
| `auth.getUser()` | `auth.currentUser` | `GET /v1/auth/user` |
| `auth.signOut()` | `signOut` | `POST /v1/auth/signout` |
| `auth.signInWithOtp({ email })` | `sendSignInLinkToEmail` | `POST /v1/auth/magiclink` |
| `auth.signInWithOAuth({ provider })` | `signInWithPopup` | The provider flow in [Google and GitHub sign-in](https://rezincore.com/docs/auth/providers.md) |

Details, bodies and answers: [Accounts and sign-in](https://rezincore.com/docs/auth/overview.md) and [Email flows](https://rezincore.com/docs/auth/email-flows.md).

## Data

| Supabase | Rezin Core |
|---|---|
| `from('todos').select('*')` | `GET /v1/data/todos` |
| `.eq('state', 'open')` | `GET /v1/data/todos?state=eq.open` |
| `.order('created_at', { ascending: false }).limit(20)` | `?order=created_at.desc&limit=20` |
| `from('todos').insert({ title })` | `POST /v1/data/todos` with the row as JSON |
| `from('todos').update({ state: 'done' }).eq('id', 7)` | `PATCH /v1/data/todos?id=eq.7` |
| `from('todos').delete().eq('id', 7)` | `DELETE /v1/data/todos?id=eq.7` |

Filters, paging and what the data API will not do: [The data API](https://rezincore.com/docs/database/data-api.md). Joins across tables and calling database functions by name are not offered through the data API; put that logic in a view, or in a [function](https://rezincore.com/docs/functions.md).

From Firestore the change is larger, because documents became rows: `collection('shops').doc('s1').get()` becomes `GET /v1/data/shops?id=eq.s1`, and a subcollection `shops/s1/orders` becomes `GET /v1/data/orders?parent_id=eq.s1`.

## Files

| Supabase | Firebase | Rezin Core |
|---|---|---|
| `storage.from('b').upload(path, file)` | `uploadBytes(ref, file)` | `PUT /v1/storage/b/<path>` with the file as the body |
| `storage.from('b').download(path)` | `getBytes(ref)` | `GET /v1/storage/b/<path>` |
| `storage.from('b').list(prefix)` | `listAll(ref)` | `GET /v1/storage/b?prefix=<prefix>` |
| `storage.from('b').remove([path])` | `deleteObject(ref)` | `DELETE /v1/storage/b/<path>` |
| `storage.from('b').createSignedUrl(path, 3600)` | `getDownloadURL(ref)` | `POST /v1/storage/b/sign` |

[Storage](https://rezincore.com/docs/storage.md) has the details.

## Live updates

| Supabase | Firebase | Rezin Core |
|---|---|---|
| `channel(...).on('postgres_changes', ...)` | `onSnapshot(query, ...)` | A WebSocket subscription to a table: [Realtime](https://rezincore.com/docs/realtime.md) |

Live updates are switched on table by table and respect row-level security: each listener is told only about rows it may read.

## Server-side code

| Supabase | Firebase | Rezin Core |
|---|---|---|
| Edge Functions (Deno) | Cloud Functions | [Functions](https://rezincore.com/docs/functions.md): one JavaScript module, `export default async (request, context) => Response` |
| Database webhooks | Firestore triggers | [Webhooks](https://rezincore.com/docs/webhooks.md), to an address or to one of your functions |
| `pg_cron` | Scheduled functions | A function's timetable |

## In your access rules

| Supabase | Rezin Core |
|---|---|
| `auth.uid()` | `core.app_user()` |
| `to authenticated` | `core.app_user() is not null` |
| (no equivalent; one project is one tenant) | `core.app_org()`, the caller's organization |

[Securing tables](https://rezincore.com/docs/database/row-level-security.md) explains organizations and has rule templates.
