Back to roadmaps supabase Course

Supabase JS SDK and RLS SQL Cheat Sheet

This quick reference guide summarizes the most common patterns and configurations in Supabase.


1. JS SDK Database Queries Cheat Sheet

// 1. Fetching rows with filtering
const { data } = await supabase
  .from("items")
  .select("id, name")
  .eq("status", "active")
  .gt("price", 50);

// 2. Inserting record rows
await supabase
  .from("items")
  .insert([{ name: "New Item", price: 99.99 }]);

// 3. Updating record rows
await supabase
  .from("items")
  .update({ price: 79.99 })
  .eq("id", 12);

// 4. Deleting record rows
await supabase
  .from("items")
  .delete()
  .eq("id", 12);

2. Authentication SDK Helpers

// A. Registering with email
await supabase.auth.signUp({
  email: "user@example.com",
  password: "securepassword",
});

// B. Logging in with email
await supabase.auth.signInWithPassword({
  email: "user@example.com",
  password: "securepassword",
});

// C. Fetching active user session
const { data: { user } } = await supabase.auth.getUser();

// D. Logging out
await supabase.auth.signOut();

3. PostgreSQL RLS Policies Templates

-- Enable RLS on a table
ALTER TABLE posts ENABLE ROW LEVEL SECURITY;

-- Policy 1: Grant public read-only access (SELECT)
CREATE POLICY "Allow public read"
ON posts FOR SELECT
USING (true);

-- Policy 2: Restrict modifications to record owners (INSERT/UPDATE/DELETE)
CREATE POLICY "Allow owners write access"
ON posts FOR ALL
TO authenticated
USING (auth.uid() = author_id)
WITH CHECK (auth.uid() = author_id);
Published on Last updated: