Skip to main content

Overview

The Users API provides endpoints for managing user profiles and retrieving favorite properties. All endpoints require authentication. Base Path: /api/users
Authentication is handled via Better Auth. All requests must include valid session cookies.

Get User Profile

const response = await api.users.getProfile();
Retrieve the authenticated user’s profile information.

Authentication

Requires valid session cookie. Returns 401 if not authenticated.

Response

success
boolean
required
Indicates if the request was successful
data
User
required
User profile object

Example Response

{
  "success": true,
  "data": {
    "id": "123",
    "email": "[email protected]",
    "name": "Juan Pérez",
    "photoURL": "https://example.com/avatar.jpg",
    "role": "user",
    "createdAt": "2024-01-15T10:30:00Z",
    "updatedAt": "2024-03-01T14:20:00Z"
  }
}

Update User Profile

const response = await api.users.updateProfile({
  name: "Juan Carlos Pérez",
  photoURL: "https://example.com/new-avatar.jpg"
});
Update the authenticated user’s profile information.

Request Body

name
string
User’s full name (max 255 characters)
photoURL
string
URL to user’s profile photo
Email and role cannot be changed through this endpoint. Contact an administrator to modify these fields.

Response

success
boolean
required
Indicates if the update was successful
data
User
required
Updated user profile object

Example Request

const response = await api.users.updateProfile({
  name: "Juan Carlos Pérez"
});

Example Response

{
  "success": true,
  "data": {
    "id": "123",
    "email": "[email protected]",
    "name": "Juan Carlos Pérez",
    "role": "user",
    "updatedAt": "2024-03-04T16:45:00Z"
  }
}

Get User Favorites

const response = await api.users.getFavorites();
Retrieve all properties favorited by the authenticated user.

Authentication

Requires valid session cookie. Returns 401 if not authenticated.

Response

success
boolean
required
Indicates if the request was successful
data
string[]
required
Array of property IDs that the user has favorited

Example Response

{
  "success": true,
  "data": ["123", "456", "789"]
}

Usage Example

From src/contexts/AuthContext.tsx:66:
const favoritesResponse = await api.users.getFavorites();
setFavoriteIds(favoritesResponse.data || []);

Usage with Property Details

From src/pages/FavoritesPage.tsx:28:
const favoritesResponse = await api.users.getFavorites();
const favoriteIds = favoritesResponse.data || [];

// Fetch full property details for each favorite
const propertiesData = await Promise.all(
  favoriteIds.map((id) =>
    api.properties.get(String(id)).catch(() => {
      console.error(`Failed to fetch property ${id}`);
      return null;
    })
  )
);

const validProperties = propertiesData
  .filter((p) => p !== null)
  .map((p) => p.data);
The favorites endpoint returns only property IDs. To display property details, you need to fetch each property using the Properties API.

Error Responses

All endpoints may return the following error responses:
error
object

Common Status Codes

  • 200 - Success
  • 400 - Bad Request (invalid parameters)
  • 401 - Unauthorized (not logged in or session expired)
  • 403 - Forbidden (insufficient permissions)
  • 404 - Not Found
  • 500 - Internal Server Error

Common Error Codes

{
  "message": "Authentication required",
  "code": "UNAUTHORIZED"
}

Build docs developers (and LLMs) love