Server Actions

How mutations work — pattern, locations, and revalidation.

Mutations use Next.js Server Actions with the Supabase server client. Actions validate the session, check membership, then write to Postgres.

Action pattern

ts
"use server";

import { createClient } from "@/lib/supabase/server";
import { revalidatePath } from "next/cache";

export async function createProject(formData: FormData) {
  const supabase = await createClient();
  const { data: { user } } = await supabase.auth.getUser();
  if (!user) throw new Error("Unauthorized");
  // ... insert hub_projects, hub_project_members
  revalidatePath("/projects");
}

Where actions live

  • lib/projects/actions.ts
  • lib/workspace/actions.ts
  • lib/tasks/actions.ts
  • lib/project-files/actions.ts
  • lib/inbox/actions.ts

Revalidation

After mutations, actions call revalidatePath() or revalidateTag() so Server Components show fresh data on the next navigation.