Profiles and Media

View saved

Goal

This snapshot advances Meridian Notes by teaching you to edit profiles and validate avatar uploads.

Every numbered folder is a complete application. Run this stage on its own, then compare it with the previous snapshot to isolate the new responsibility.

Prerequisites

Use Node.js 20 or newer, npm, and a terminal. You should be comfortable with JavaScript functions, objects, modules, and basic HTML forms.

The development server uses port 3000. Data-backed snapshots use PostgreSQL on host port 5433 and keep their data in a database unique to that folder.

  • Node.js and npm installed
  • A code editor and terminal
  • Docker from part 4 onward

Concepts

Profile updates require an authenticated id and an allowlist of editable fields. Media handling must constrain MIME type and size and avoid trusting the original filename.

Keep the server boundary visible: Server Components may read trusted data directly, while Server Actions and route handlers must validate all incoming values and re-check authorization.

Walkthrough

Load the current profile, validate name and bio, generate a safe image filename, save the upload, update Prisma, and revalidate the route.

Trace the example from request to rendered result, then inspect the matching snapshot for its surrounding types, validation, error handling, and configuration.

if (!image.type.startsWith("image/") || image.size > 2_000_000) {
  throw new Error("Image must be under 2 MB");
}

Run and verify

Enter 08-Profiles-And-Media, install its dependencies, and copy .env.example when the snapshot includes one.

Open http://localhost:3000. Keep the terminal visible so framework, Prisma, and authentication errors can be matched to the browser action that caused them.

git clone https://github.com/michaeldunga1/fcc-nextjs-blog.git
cd fcc-nextjs-blog/08-Profiles-And-Media
npm install
cp .env.example .env
docker compose -f ../docker-compose.yml up -d
npm run db:migrate
npm run db:seed
npm run dev

Troubleshooting

Use multipart form encoding and ensure the input name matches the Server Action. Local files work for learning but are ephemeral on serverless hosts.

A missing-module error usually means npm ran in another snapshot. Database errors often mean Docker is stopped, the environment file is missing, or this folder points at the wrong numbered database.

  • Read the first error first
  • Restart after environment changes
  • Never commit .env or node_modules

Try this

Upload a valid image, then confirm a text file and oversized image are rejected.

Test one expected path and one invalid or unauthorized path. A production-minded app gives useful feedback without exposing secrets or stack traces.

  • Make one focused change
  • Verify it in the browser
  • Continue only after this snapshot works

Next: Posts CRUD and Ownership

Comments

One comment per signed-in account. Comments are saved with this page’s URL.