You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow users to edit their profile information (display name, bio, school, graduation year, Instagram, profile picture). Currently profile pages only display information but have basic edit functionality that needs improvement.
Direct authenticated users to their profile page after successful login or signup.
Current State
✅ Basic edit profile modal exists in /app/user-page/page.tsx with:
Form fields for firstName, lastName, headline, school, year, Instagram
Client-side only (doesn't persist to database)
Works for demonstration but needs backend integration
Update Login Success Redirect (/app/login/page.tsx or /app/api/auth/[...nextauth]/route.ts):
After successful login, redirect to /user-page/${session.user.username}
Configure NextAuth callbacks:
callbacks: {asyncsignIn({ user }){returntrue;// Allow sign in},asyncredirect({ url, baseUrl }){// After sign in, redirect to user's profileconstsession=awaitgetServerSession(authOptions);if(session?.user?.username){return`${baseUrl}/user-page/${session.user.username}`;}returnbaseUrl;}}
Update Signup Success Redirect (/app/sign-up/page.tsx or /app/api/auth/signup/route.ts):
After successful signup and auto-login, redirect to /user-page/${username}
Add redirect logic after user creation:
// After creating user, sign them in and redirectconstsignInResult=awaitsignIn('credentials',{
username,
password,redirect: false});if(signInResult?.ok){router.push(`/user-page/${username}`);}
Move Static User Page (/app/user-page/page.tsx):
Move current /app/user-page/page.tsx content to /app/user-page/[username]/page.tsx
Convert to dynamic route that fetches user-specific data
Show "Edit Profile" button only when isOwnProfile === true
exportasyncfunctionPATCH(req: Request,{ params }: {params: Promise<{id: string}>}){try{const{ id }=awaitparams;constsession=awaitgetServerSession(authOptions);// Only allow users to edit their own profileif(!session||session.user.id!==id){returnNextResponse.json({message: 'Unauthorized'},{status: 403});}constbody=awaitreq.json();const{ firstName, lastName, headline, school, year, instagram, bio }=body;// Construct display_name from firstName and lastNameconstdisplay_name=`${firstName?.trim()||''}${lastName?.trim()||''}`.trim();constupdatedProfile=awaitprisma.profile.update({where: {user_id: id},data: {
display_name,bio: bio||headline,// Use headline as bio if bio not provided// Note: school, year, instagram need to be added to Profile model}});returnNextResponse.json({profile: updatedProfile},{status: 200});}catch(error){console.error('Profile update error:',error);returnNextResponse.json({message: 'Failed to update profile'},{status: 500});}}
Objective
Current State
✅ Basic edit profile modal exists in
/app/user-page/page.tsxwith:/user-page)Part 1: Authentication Redirect to User Profile
Tasks
Create Dynamic User Profile Route (
/app/user-page/[username]/page.tsx):Update Login Success Redirect (
/app/login/page.tsxor/app/api/auth/[...nextauth]/route.ts):/user-page/${session.user.username}Update Signup Success Redirect (
/app/sign-up/page.tsxor/app/api/auth/signup/route.ts):/user-page/${username}Move Static User Page (
/app/user-page/page.tsx):/app/user-page/page.tsxcontent to/app/user-page/[username]/page.tsxisOwnProfile === truePart 2: Profile Edit Backend Integration
Tasks
Implement PATCH /api/users/[id] (
/app/api/users/[id]/route.ts):Update Prisma Schema (
/prisma/schema.prisma):npm run db:pushto update databaseUpdate Edit Profile Form (
/app/user-page/[username]/page.tsx):Add Profile Picture Upload (Optional - Cloudinary integration):
Add Form Validation:
Add Success/Error States:
Update Navbar/Header:
session.user.username/user-page/${session.user.username}Testing Checklist
Authentication Redirect Tests
/user-page/[username]/user-page/[username]Profile Edit Tests
Security Tests
/api/users/[another-user-id]PATCH → gets 403