Put in order · Vibe coding with Claude Code course · Module 15: Advanced Claude Code
Sorting: Locks in the edit route
Arrange the lines of the PATCH /api/pins/[id] handler so that a stranger gets a refusal before the server reads the data from the request body:
Items to put in order
- if (!viewerId) return Response.json({ error: "Sign in." }, { status: 401 });
- return Response.json(pin);
- const viewerId = await getCurrentUserId();
- const result = pinEditSchema.safeParse(body);
- const ownerId = await getPinOwner(id);
- if (ownerId !== viewerId) return Response.json({ error: "Only the author edits a pin." }, { status: 403 });
You can check the correct answer by solving this task in the CodeWorlds game.