Skip to content
PromptPilot AI

Library / Coding & Technology / API

Next.js: secure route handler / server action

Validated, authenticated mutation endpoint.

Cursor / coding agentsClaude CodeChatGPTClaudenextjs
Who it's for
Developers using AI coding tools
Use case
API
Output
Agent task · Free
You'll need to fill in
route handler / server actionmutation
Prevents: Server action trusts client input and skips auth because 'it's server code'.
Create a [route handler / server action] that [mutation].
- Validate input with zod; return 400 with field errors on failure.
- Verify the user session on the server and check they own the resource.
- Return typed JSON (route handler) or a typed result object (server action).
- Revalidate affected paths/tags after mutation, using the APIs documented for this Next.js version.
- Add a test for success, validation error and unauthorised.

Copies your prompt and opens the official site in a new tab. You may need to paste it yourself (Ctrl/⌘ + V). Nothing is sent to the AI by us.

Replace [bracketed] parts with your own details before sending. Want it tailored? Build a custom website & app development prompt.

Before vs after

A typical one-line request compared with this prompt. We only show sample responses where we've written an illustration.

BeforeWhat people usually type

Prompt

api

1 words · no role, context, format or constraints

AfterThis library prompt

Prompt

Create a [route handler / server action] that [mutation].
- Validate input with zod; return 400 with field errors on failure.
- Verify the user session on the server and check they own the resource.
- Return typed JSON (route handler) or a typed result object (server action).
- Revalidate affected paths/tags after mutation, using the APIs documented for this Next.js version.
- Add a test for success, validation error and unauthorised.

72 words · generated instantly from templates, no AI called

What we added

  • Your details: [brackets] for the facts only you know

Related prompts