Overview
The Customer Addresses API provides comprehensive address management functionality for customers, including creating, updating, deleting, and managing delivery addresses. This system supports multiple addresses per customer with default address selection and geographic information. Location:convex/customers/addresses.ts
Create Address
Create a new delivery address for a customer.The ID of the customer to create the address for
A descriptive name for the address (e.g., “Home”, “Office”)
The complete address string
The ID of the city for this address
The ID of the area within the city
Flat or villa number
Building name or number
Nearby landmark for easier location
GPS latitude coordinate
GPS longitude coordinate
Whether this should be the default address for the customer
Id<'customerAddresses'> - The ID of the newly created address
Update Address
Update an existing customer address. Only provided fields will be updated.The ID of the address to update
Updated address name
Updated full address
Updated city ID
Updated area ID
Updated flat/villa number
Updated building name/number
Updated landmark
Updated latitude
Updated longitude
Whether this should be the default address
Whether the address is active
null
Delete Address
Delete a customer address.The ID of the address to delete
null
Get Customer Addresses
Retrieve all active addresses for a customer, sorted with default address first.The customer ID. If not provided, uses the authenticated user’s customer profile
Get Address
Retrieve a specific address by ID with full details.The ID of the address to retrieve
null if not found:
Set Default Address
Set a specific address as the default for a customer. This will unset any existing default address.The ID of the address to set as default
null
Authentication & Authorization
All address operations require authentication and implement proper authorization:- User Authentication: All functions verify the user is authenticated through Clerk
- Ownership Verification: Users can only manage their own addresses
- Customer Association: Addresses are tied to customer profiles, which are linked to authenticated users
Default Address Management
The system automatically manages default addresses:- Only one address per customer can be marked as default
- Setting a new default automatically unsets the previous default
- Default addresses appear first in address listings
- Default address logic is handled in
createAddress,updateAddress, andsetDefaultAddress
Geographic Information
Addresses include geographic data for delivery optimization:- City and Area References: Links to city and area entities for structured location data
- GPS Coordinates: Optional latitude/longitude for precise location
- Address Validation: Ensures referenced cities and areas exist before creating/updating addresses
Error Handling
Common error scenarios:- Unauthorized: User not authenticated or trying to access another user’s addresses
- Not Found: Address, city, or area doesn’t exist
- Invalid References: Invalid city or area IDs provided
- Ownership Mismatch: Attempting to modify addresses belonging to other customers
