Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

JavaScript

The client is v2/sdks/js, package name @reactor/client. It is not published. Depend on it from the repo, or copy the src/ modules. It needs @supabase/postgrest-js, which is how data queries are built.

import { createClient } from "@reactor/client"
const reactor = createClient("https://<ref>.apps.localhost:18000", anonKey, {
session: savedSession, // optional
})

The first argument is the project origin with no trailing slash. The second is the anon key. Options are fetch and an initial session.

const session = await reactor.auth.signUp({ email, password })
const session = await reactor.auth.signInWithPassword({ email, password })
const user = await reactor.auth.getUser()
const session = await reactor.auth.refreshSession()
await reactor.auth.signOut()
reactor.auth.getSession()

A session is { access_token, refresh_token, user: { id, email } }. The client keeps it in memory. Persist it yourself if the page should survive a reload. Later calls send the access token. Before sign-in they send the anon key.

signInWithOAuth throws. OAuth is not implemented.

reactor.from(table) and reactor.rpc(name, args) return the PostgREST client pointed at /data/v1.

const { data, error } = await reactor
.from("todos")
.select("*")
.eq("user_id", session.user.id)
.order("created_at", { ascending: false })
const inserted = await reactor
.from("todos")
.insert({ title, user_id: session.user.id })
.select()

Errors from PostgREST come back as { error } on the query result. Auth and storage throw ReactorError with status and message.

await reactor.storage.from("files").upload(path, body, { contentType: "text/plain" })
const bytes = await reactor.storage.from("files").download(path)
const result = await reactor.functions.invoke("ping", { body: { hello: "world" } })

Upload and download presign, then call the signed URL. Invoke is POST /fn/v1/{name} and returns the JSON body.