Profile API
The Profile API allows authenticated users to view and update their profile information. Profiles are automatically created on first access.Authentication
All endpoints require:- Valid user session
- Session cookie or Bearer token
Get user profile
Retrieve the authenticated user’s profile. If no profile exists, one is created automatically. Endpoint:GET /api/profile
string
Profile UUID
string
User ID (references auth user table)
string
User’s full name
text
User biography/description
string
Profile picture URL
string
User location (city, region)
string
User website URL
string
Preferred language code:
"fr", "en", "ar", or "es"timestamp
Profile creation timestamp
timestamp
Last update timestamp
Update user profile
Update the authenticated user’s profile. Only specified fields are updated. Endpoint:PATCH /api/profile
string
User’s full name
text
Biography or description
string
Profile picture URL
string
Location (city, region, country)
string
Personal website URL
string
Language preference:
"fr", "en", "ar", or "es"Auto-creation behavior
When a user first accesses their profile viaGET /api/profile:
- Profile exists: Returns existing profile
- No profile: Automatically creates one with:
fullNamepopulated from auth user’s namepreferredLanguageset to"fr"(default)- Other fields set to
null
Validation rules
The API validates update requests:- Allowed fields only: Only the 6 editable fields can be updated
- No userId changes: The
userIdfield is immutable - Type checking: Fields must match expected types
- SQL injection prevention: All inputs are parameterized
Response codes
success
Profile retrieved or updated successfully
error
Invalid request body (malformed JSON)
error
Unauthorized - valid session required
error
Database error or internal server error
Error responses
Implementation reference
Source:/src/pages/api/profile/index.ts
The profile endpoint:
- Uses Better Auth session validation
- Queries the
profiletable with Drizzle ORM - Auto-creates profiles on first GET request
- Validates updates against a whitelist of allowed fields
- Sets security headers (
X-Content-Type-Options: nosniff)
Database schema
The profile table structure:The
preferredLanguage field integrates with the i18n system. When set, the application UI will display in the user’s preferred language across all routes.