Server actions keep sensitive code and secrets on the server, so users cannot see or change them. This reduces risks like exposing API keys or business logic.
Without validation, attackers can send harmful data that exploits vulnerabilities like SQL injection or cross-site scripting.
export async function addUser(data) { await db.users.insert(data); return { success: true }; }
The function directly inserts user data without checking it. This can lead to storing harmful or malformed data.
Option A correctly awaits the async user fetch, checks for falsy user, and throws an error to block unauthorized access.
Performing security checks right after receiving the request prevents unauthorized or malicious actions early, saving resources and improving security.
