What this thread does
Do first: put authentication, authorization and field validation inside the profile Server Action. Next.js forms
Short answer
Use a Server Action for profile fields and useActionState for errors and pending feedback. Next.js forms Use an UploadThing FileRoute for the image, authenticating in middleware and handling completion separately from the text-field save. UploadThing setup
Choose / don't choose
- Server Action: choose for server-side validation; don't treat client
requiredor email-type checks as the whole validation boundary. Next.js forms - UploadThing: choose for an image route with upload callbacks; don't copy the guide's fake authentication function into the application. Setup
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
safeParse | Parse submitted field values; return errors on failure | Server Action | Next.js forms |
Submit disabled | pending | useActionState form | Next.js forms |
image.maxFileSize | 4MB in the example, not a required avatar policy | UploadThing FileRoute | Setup |
image.maxFileCount | 1 in the example | UploadThing FileRoute | Setup |
endpoint | Match your FileRoute key; example imageUploader | UploadButton | Setup |
Order of operations
1. Read submitted fields, validate them on the server, and return errors before mutation on failure. Render action state beside the form. Next.js forms 2. Configure the image route and authenticated middleware; throwing prevents upload. Carry the authenticated user ID in metadata. Setup 3. Export GET and POST with createRouteHandler and generate a typed UploadButton from the FileRouter. Setup 4. Handle onUploadComplete on the server, and onClientUploadComplete and onUploadError in the client. The server callback receives file.ufsUrl. Setup
Known failures and fixes
| Symptom | Cause | Fix | Source |
|---|---|---|---|
| Submit remains active during save | Pending state is not used | Bind button disabling to pending | Next.js forms |
| Upload fails without feedback | Client error callback is absent | Render a message from onUploadError | Setup |
Missing
- How should the completed image be persisted as this user's avatar, and previous images removed? The setup shows completion metadata, not that account-data lifecycle.
- How should uploaded images and text-field saves recover from partial failure? These sources do not define an atomic save strategy.
- Cropping, upload progress UI, retained text after failed requests and email-change confirmation need additional guidance beyond these pages.
Checked
2026-11-23: read Next.js forms and UploadThing App Router setup.
Started from a post by @WhatWorks editors, packaged by the editor.