Skip to content

Fix #2: Add user avatar upload and display#3

Open
cosmo-coderbots[bot] wants to merge 1 commit into
mainfrom
fix/issue-2-user-avatars
Open

Fix #2: Add user avatar upload and display#3
cosmo-coderbots[bot] wants to merge 1 commit into
mainfrom
fix/issue-2-user-avatars

Conversation

@cosmo-coderbots

Copy link
Copy Markdown

Summary

Adds user avatar support. Users can now upload a profile photo, which appears next to their username in the feed, composer, and site header. Users without an uploaded avatar keep the existing initial-letter placeholder.

Fixes #2

Changes

  • New /profile page with an avatar upload form (+ remove button)
  • New server actions uploadAvatar (5 MB image cap, mime-type check) and removeAvatar in app/actions.ts
  • New route handler app/api/avatars/[username]/route.ts that serves the image bytes straight from Postgres, matching the existing /api/images/[id] pattern
  • users.avatar, users.avatar_type, users.avatar_updated_at columns added to db/schema.sql (ALTER TABLE … ADD COLUMN IF NOT EXISTS so existing DBs migrate cleanly)
  • Shared <Avatar> component with letter-fallback; renders with ?v=<avatar_updated_at> so browsers pick up updated avatars without a hard refresh
  • Feed query and getCurrentUser extended to return avatar_updated_at

Test plan

  • npm run lint — clean
  • npm run build — succeeds
  • tsc --noEmit — clean
  • Manual: logged in as alice, uploaded avatar via /profile → avatar shows in header, composer, and every post authored by alice
  • Manual: logged in as bob, uploaded a different avatar → both users' avatars render correctly, users without avatars still show initial-letter fallback
  • Manual: verified /api/avatars/alice returns the uploaded PNG with the correct Content-Type

Before

before

After (feed with mixed avatars + fallbacks)

after

Profile page

profile

🤖 Generated with Claude Code

Users can now upload a profile photo that's shown next to their username
in the feed, composer, and site header.

- New /profile page with an avatar upload form + remove button
- New POST server actions: uploadAvatar (5MB image cap) and removeAvatar
- New route handler /api/avatars/[username] serving the bytes from Postgres
- users.avatar / avatar_type / avatar_updated_at columns (idempotent
  ALTER TABLE ADD COLUMN IF NOT EXISTS for existing databases)
- Shared Avatar component with initial-letter fallback for users who
  haven't uploaded one yet; ?v=<timestamp> cache-bust so refreshed
  avatars appear immediately

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add user avatar support

1 participant