Server Actions are functions that run on the server and can be invoked from forms or client components. Treat them like public endpoints: validate input and enforce auth/authorization on the server (don’t rely on the UI).
Server Actions are server-side functions (typically marked with `'use server'`) that can be called from:
They run on the server, so they can access secrets, databases, and internal services. They also integrate with cache invalidation (`revalidatePath`, `revalidateTag`) after mutations.
'use server'
export async function updateName(formData: FormData) {
const name = String(formData.get('name') ?? '')
if (name.length < 2) throw new Error('Invalid name')
const user = await requireUser()
await db.user.update({ where: { id: user.id }, data: { name } })
}Treat a Server Action like a **public API endpoint**: