POST /api/users/sync
Synchronize user data to database
POST
Authentication
Not Required (No[Authorize] attribute)
Public endpoint for user synchronization
Request Body
User UUIDValidation (Lines 25-28):Constraints:
- MUST be valid GUID format
- MUST NOT be empty or null
User email addressValidation: None in controllerNullable: Allowed (passed to service as-is, Line 30)
User display nameValidation: None in controllerNullable: Yes (Line 51)
User phone numberUsage: NOT USED (Line 50)Note: Accepted in request but not passed to service
User avatar image URLUsage: NOT USED (Line 52)Note: Accepted in request but not passed to service
Authentication provider nameUsage: NOT USED (Line 53)Note: Accepted in request but not passed to service
Side Effects
Database Mutations (Line 30):userstable (UPSERT operation)
id: User UUID (primary key)email: User email (from request)name: User display name (from request)updated_at: Current timestamp
Authorization
No Authentication: Endpoint publicly accessible Security Risk: Anyone can sync user data- No ownership verification
- No rate limiting documented
- Potential for abuse
Permissions
Who Can Sync:- Anyone (no authentication required)
- User ID, email, name only
- phone, avatarUrl, provider silently ignored
Edge Cases
- Invalid GUID: 400 error (Lines 25-28)
- Null email: Allowed, passed to service (Line 30)
- Null name: Allowed, passed to service (Line 30)
- Empty string email: Allowed (no validation)
- Empty string name: Allowed (no validation)
- User already exists: Updated (UPSERT operation)
- User doesn’t exist: Created (UPSERT operation)
- Concurrent syncs: Last write wins (no locking documented)
Error Conditions
| Code | HTTP | Cause | Controller Line |
|---|---|---|---|
| N/A | 400 | Invalid GUID format | 25-28 |
| N/A | 500 | Service exception | 38-42 |
- Exception details NOT exposed (unlike other endpoints)
- Logged internally (Line 40 comment)
Behavioral Guarantees
Idempotency: YES- Multiple calls with same data have same effect
- UPSERT operation ensures idempotency
- Safe to retry
- No merge logic
- Previous values lost
Validation Rules
Controller-Level Validation:- ✅ ID format (GUID)
- ❌ Email format (not validated)
- ❌ Name length (not validated)
- ❌ Required fields (only ID required)
Response Format
Success Response (Lines 32-36):- Echoes
idandemailfrom request - Adds
synced: truefield nameNOT echoed in response
- Generic error message
- No details exposed
Use Cases
Authentication Integration:- Called after Supabase Auth signup
- Called after JWT login
- Ensures user exists in application database
- Creates user row before creating threads
- Required for foreign key constraints
- Updates email/name if changed in auth system
Security Implications
Public Endpoint:- No authentication required
- Potential for data pollution
- Could be rate-limited at infrastructure level
- Email addresses can be synced by anyone knowing user ID
- NOT designed for direct client calls
- Should be called by backend after auth verification
Unused Fields
Accepted but Ignored (Lines 50-53):phone: Defined in request model, not usedavatarUrl: Defined in request model, not usedprovider: Defined in request model, not used
- Controller only uses id, email, name