Supabase
Give your extension accounts, persistent data, file storage, and private server logic through one typed client.
Start the local Supabase backend before using these helpers.
Auth — sign users in and keep them signed in
Use email/password or OAuth without rebuilding session persistence for Manifest V3. Read the current user on mount and subscribe when several surfaces must react to sign-in, sign-out, or token refresh.
import { auth } from "@/integrations/supabase";
// Sign in, sign up, sign out
await auth.signIn(email, password);
await auth.signUp(email, password);
await auth.signInWithOAuth("google");
await auth.signOut();
// Check session
const user = await auth.getUser(); // { id, email } | null — use on mount
const signedIn = await auth.isAuthenticated();
const session = await auth.getSession(); // full token, user, expiry
// Listen for changes across all surfaces
auth.onChange((session) => {
if (session.isAuthenticated) showApp(); else showLogin();
});Database — read and write user data (RLS-scoped)
The db helper exposes the Supabase query builder. Protect every user-facing table with Row-Level Security so the same frontend call only returns rows the signed-in user may access.
import { db } from "@/integrations/supabase";
const { data } = await db.from("notes").select("*");
await db.from("notes").insert({ title: "Hello" });
await db.from("notes").update({ title: "Updated" }).eq("id", 1);
await db.from("notes").delete().eq("id", 1);Edge Functions — server-side logic with secrets
Call private server logic without putting API keys in the extension. functions.invoke sends JSON, attaches the current session, and returns parsed data.
import { functions } from "@/integrations/supabase";
const result = await functions.invoke("hello-world", { name: "World" });Use functions.raw when you need the original Response, such as a download or custom headers.
const response = await functions.raw("download-report", {
method: "POST",
body: { id: "123" },
});
const blob = await response.blob();Storage — upload, download, serve files
Upload avatars, exports, and attachments to Supabase buckets. Public files get stable URLs; private files get short-lived signed URLs.
import { storage } from "@/integrations/supabase";
await storage.upload("avatars", "user-1.png", file, { upsert: true });
const blob = await storage.download("exports", "report.pdf");
const url = storage.getPublicUrl("avatars", "user-1.png");
const signed = await storage.createSignedUrl("private", "doc.pdf", 120);Next
Set up the local Supabase stack. Combine with Stripe for payments or AI for intelligent features. Add your production credentials when you're ready to deploy.
