Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 31 ยท Practice and Review

Firebase and Supabase Cheat Sheet

A side-by-side cheat sheet of everyday tasks in the Firebase and Supabase SDKs, the CLI commands you need and a security checklist, with two small demos.

This is the page to keep open while you work. It lists the same everyday tasks side by side for Firebase (modular JavaScript SDK, v9 style and later) and Supabase (supabase-js v2), the most-used command line steps, and a security checklist. Everything here is read-only reference: the real services need an account, so none of it runs on this site. Two small stand-ins at the end (ours, not part of either product) turn the checklist into something you can try.

SDK details change between versions, so when a call looks different from your installed version, trust the official documentation for that version. Each row links to the lesson that explains the idea.

Same job, two vocabularies

Firebase Documents, collections, rules.
Supabase Tables, rows, policies.

Learn the idea once, then translate.

1 / 2

Setup

Task Firebase Supabase
Install npm install firebase npm install @supabase/supabase-js
Initialize initializeApp(config) then getFirestore(), getAuth() createClient(url, anonKey)
Public identifier config object (apiKey, projectId) project URL + anon/publishable key
Server secret service account (Admin SDK) service role key
JavaScript
// read-only
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
const app = initializeApp({ apiKey: "โ€ฆ", projectId: "โ€ฆ" });
const db = getFirestore(app);

import { createClient } from "@supabase/supabase-js";
const supabase = createClient(import.meta.env.VITE_SUPABASE_URL, import.meta.env.VITE_SUPABASE_ANON_KEY);

See Creating Projects and Using the SDKs.

Authentication

Task Firebase Supabase
Sign up createUserWithEmailAndPassword(auth, email, pw) supabase.auth.signUp({ email, password })
Sign in signInWithEmailAndPassword(auth, email, pw) supabase.auth.signInWithPassword({ email, password })
OAuth signInWithPopup(auth, new GoogleAuthProvider()) supabase.auth.signInWithOAuth({ provider: "google" })
Magic link sendSignInLinkToEmail(auth, email, settings) supabase.auth.signInWithOtp({ email })
Current user auth.currentUser (await supabase.auth.getUser()).data.user
Watch session onAuthStateChanged(auth, cb) supabase.auth.onAuthStateChange(cb)
Sign out signOut(auth) supabase.auth.signOut()
Roles custom claims (Admin SDK) app_metadata or roles table

Lessons: Email and Password Sign-In, OAuth, Magic Links and JWTs, Users, Roles and Custom Claims.

Data

Task Firebase (Firestore) Supabase (Postgres)
Add with auto id addDoc(collection(db, "notes"), data) .from("notes").insert(data)
Set known id setDoc(doc(db, "notes", id), data) .from("notes").upsert({ id, ...data })
Update fields updateDoc(ref, { title }) .from("notes").update({ title }).eq("id", id)
Delete deleteDoc(ref) .from("notes").delete().eq("id", id)
Read one getDoc(ref) .from("notes").select().eq("id", id).single()
Read many getDocs(query(...)) .from("notes").select()
Filter where("done", "==", false) .eq("done", false)
Sort orderBy("created", "desc") .order("created", { ascending: false })
Limit limit(20) .limit(20) or .range(0, 19)
Next page startAfter(lastDoc) .range(20, 39) or a .lt() cursor
Counter increment(1) an RPC or SQL update โ€ฆ set n = n + 1
Server time serverTimestamp() default now() column
Related data denormalize or extra reads .select("*, author(name)")
Atomic multi-write writeBatch, runTransaction RPC (SQL function) or begin โ€ฆ commit

Lessons: Reading and Writing Documents, Queries, Indexes and Pagination, Querying with supabase-js.

Realtime

Task Firebase Supabase
Subscribe to changes onSnapshot(query, cb) supabase.channel("x").on("postgres_changes", { event: "*", schema: "public", table: "notes" }, cb).subscribe()
Unsubscribe call the function onSnapshot returned supabase.removeChannel(channel)
Presence build it with documents and onDisconnect (Realtime Database) channel.track({...}) with presence events
Offline built in (persistent cache) not built in

For Supabase, a table must be added to the supabase_realtime publication for postgres_changes to work. See Realtime Listeners and Offline Support and Supabase Realtime and Postgres Changes.

Security syntax

Text
// read-only: Firestore rules, owner-only
match /notes/{id} {
  allow read, write: if request.auth != null && resource.data.ownerId == request.auth.uid;
  allow create: if request.auth != null && request.resource.data.ownerId == request.auth.uid;
}
SQL
-- read-only: Supabase RLS, owner-only
alter table notes enable row level security;
create policy "own rows" on notes for select using ((select auth.uid()) = owner_id);
create policy "own inserts" on notes for insert to authenticated
  with check ((select auth.uid()) = owner_id);

Lessons: Firestore Security Rules, Row Level Security Policies.

Storage and functions

Task Firebase Supabase
Upload uploadBytes(ref(storage, path), file) supabase.storage.from("bucket").upload(path, file)
Public URL getDownloadURL(ref) .getPublicUrl(path)
Temporary URL signed URL from Admin SDK .createSignedUrl(path, 60)
Call a function httpsCallable(functions, "name")(data) supabase.functions.invoke("name", { body })
Runtime Node.js (Cloud Functions) Deno (Edge Functions)

Lessons: File Storage and Uploads, Cloud Functions and Edge Functions.

CLI commands

Task Firebase CLI Supabase CLI
Log in firebase login supabase login
Initialize a folder firebase init supabase init
Run locally firebase emulators:start supabase start (needs Docker)
Deploy rules firebase deploy --only firestore:rules supabase db push (schema and policies)
Deploy functions firebase deploy --only functions supabase functions deploy name
Host the site firebase deploy --only hosting use any static host
Create a migration n/a (rules and indexes are files) supabase migration new name
Set a secret firebase functions:secrets:set NAME supabase secrets set NAME=value

See Hosting, Deploying and Environments.

Security checklist

  • Rules are not in test mode; no allow ... if true left over.
  • RLS is enabled on every table in an exposed schema, each with deliberate policies.
  • with check (or request.resource comparisons) stops changing protected fields.
  • Roles come from custom claims, app_metadata or a protected table.
  • The service role key and Admin credentials exist only on servers.
  • Views are created with security_invoker, and security definer functions are reviewed.
  • Storage buckets have access rules plus size and type limits.
  • App Check or rate limits are on; budget alerts are set.
  • Negative tests exist: guest, wrong user, missing claim.

More detail in Security Pitfalls in Both Platforms.

Two stand-ins

This first stand-in prints the translation of one task between the two vocabularies, as a tiny lookup. It is a convenience of ours, not an official tool.

JS Translate a task

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The second turns part of the checklist into code: give it a description of a project and it lists the problems. Real audits need real tools, but the habit of checking mechanically is the point.

JS Checklist as code

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which Supabase call watches table changes?

    Channels with postgres_changes events deliver row changes in realtime.
  2. 2. What is the Firestore counterpart of an atomic counter update?

    increment applies the change on the server so concurrent updates do not overwrite each other.
  3. 3. Which command starts a local Supabase stack?

    supabase start runs the local services in Docker.
  4. 4. Which key must never appear in client code?

    The service role bypasses RLS, so a leak exposes every row.

Summary

  • Most tasks have a one-to-one translation between the SDKs; the data models differ.
  • Public keys identify a project; service keys and Admin credentials are server-only.
  • Local emulators and supabase start let you test rules and policies before deploying.
  • Turn the security checklist into automated tests where you can.

You have reached the end of the track. Revisit Practice Exercises with Solutions or the Interview Questions any time.