## Problem
- ProfilePeopleTab showed "Profile Not Found" when clicking on followed users
- Server logs showed requests to `/profiles/adelina1996gry@gmail.com`
- Root cause: `handle_new_user()` function set username to full email instead of email prefix
## Solution
1. Created migration to fix `handle_new_user()` function:
- Changed from `COALESCE(NEW.email, ...)` to `COALESCE(SPLIT_PART(NEW.email, '@', 1), ...)`
- This extracts username from email (part before @)
2. Created and ran script to fix existing profiles:
- Fixed profile: adelina1996gry@gmail.com → adelina1996gry
- Ensures uniqueness by adding numeric suffix if needed
## Files
- supabase/migrations/20251119_fix_username_email_issue.sql - Migration for function fix
- scripts/fix-username-emails.js - Script to update existing profiles
- scripts/fix-handle-new-user-function.sql - Manual SQL if needed
- scripts/apply-function-fix.js - Attempted API approach
## Testing
✓ Profile links now work: `/profiles/adelina1996gry` instead of 404
✓ No more `/profiles/undefined` requests
✓ ProfilePeopleTab displays correctly
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>