BE - Create API to View Another User's Profile #64
Labels
ansopedia
backend
database
enhancement
New feature or request
good first issue
Good for newcomers
hacktoberfest
Milestone
Description:
We need to implement an API that allows authenticated users to view another user’s profile. The endpoint should handle profile visibility, account verification, and restrict access to sensitive fields when necessary.
Users should have control over their profile's visibility (public or private). By default, profiles are public, but sensitive information (e.g., email, phone number) must always remain private.
Key Requirements:
1. View Another User’s Profile API:
Implement the
GET /users/:username
route to view profiles based on username.Authenticate the requesting user via
validateAccessToken
middleware.Example route:
2. User Data Retrieval:
3. Profile Visibility:
Check the
isPublic
flag for the requested profile:If
isPublic: true
, return the profile data with restricted fields.If
isPublic: false
, return:4. Unverified Account:
When user A attempts to view user B's profile, and user B's account is unverified (i.e.,
isEmailVerified: false
), the API should respond with a403 Forbidden
status code and the following message:5. Profile Not Found:
404 Not Found
response if the profile does not exist or if the username is invalid:6. Restricted Fields:
Only expose the following fields for public profiles:
bio
profilePictureUrl
socialLinks
(e.g., Twitter, LinkedIn, GitHub)username
Sensitive fields such as
dob
,email
,address
, andphoneNumber
should never be exposed.Example response:
7. Test Cases:
404
for non-existent or invalid profiles.Tasks:
viewProfileByUsername
inProfileController
.GET /users/:username
route inprofile.route.ts
.ProfileService
.validateAccessToken
for authentication.#19, #63
The text was updated successfully, but these errors were encountered: