Card · Server Actions
Mutation entry: validate → authorize → entity → revalidate.
Sequence
- Read session/permissions.
- Validate input; authorize.
- Call entity action; revalidatePath.
Skeleton
"use server";
export async function createProjectAction(formData) {
const session = await getSession();
if (!session) throw new Error("Unauthorized");
await createProject(formData, session.user.id);
revalidatePath("/projects");
revalidateTag("projects");
}Next 16 Security
- Every Server Action is auto-exposed as a
POSTendpoint — always authorize at the top. - Use session + role checks on every action, not just UI guards.
- Webhooks → Route Handlers with signature verification; not Server Actions.
- Prefer
revalidateTagfor data-dependent routes over broadrevalidatePath.
Study Card · Chapter 04-server-actions