Learn Everything

Paths/Frontend Engineer/Forms & Validation / Server-Side Validation

Practice Taskintermediateubuntu:24.04Ask AI

Validate on the Server

The client can be bypassed, so the server validates the same schema and maps the failure back to the form. Write the action.

Validator

⏱ 0:00

IDLE — checks run live as you type commands; submit when done

01Requirements

live checks
  • File ~/app/forms/server-action.ts exists○
  • The action parses the payload with the shared schema○
  • The action maps a failure back to the form errors○

02Walkthrough

1 of 2 revealed
  1. 01

    Write the action

    The action takes the form data, parses it with the same schema the client used, and returns either the result or the field errors.

    echo '"use server action";\n\nimport { checkoutSchema } from "./schema";\n\nexport async function submitCheckout(formData: FormData) {\n const parsed = checkoutSchema.safeParse(Object.fromEntries(formData));\n if (!parsed.success) {\n return { fieldErrors: parsed.error.flatten().fieldErrors };\n }\n return { ok: true, orderId: await createOrder(parsed.data) };\n}' > ~/app/forms/server-action.ts
  2. 1 locked · each failed submit reveals one

03Stuck?

0 of 3 revealed

Take a hint without losing the lab — each one points at the thing to look at, not at the answer.

04AI Tutor

guides, never solves

Tell me what you're stuck on — I'll nudge, not solve. Which requirement are you looking at?

04Notebook

saved locally in this browser

learner@lab — ubuntu:24.04

↑/↓ recalls commands · Ctrl+Enter submits · type help for the command list