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.Id<'customers'>
required
The ID of the customer to create the address for
string
required
A descriptive name for the address (e.g., “Home”, “Office”)
string
required
The complete address string
Id<'cities'>
required
The ID of the city for this address
Id<'areas'>
required
The ID of the area within the city
string
Flat or villa number
string
Building name or number
string
Nearby landmark for easier location
string
GPS latitude coordinate
string
GPS longitude coordinate
boolean
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.Id<'customerAddresses'>
required
The ID of the address to update
string
Updated address name
string
Updated full address
Id<'cities'>
Updated city ID
Id<'areas'>
Updated area ID
string
Updated flat/villa number
string
Updated building name/number
string
Updated landmark
string
Updated latitude
string
Updated longitude
boolean
Whether this should be the default address
boolean
Whether the address is active
null
Delete Address
Delete a customer address.Id<'customerAddresses'>
required
The ID of the address to delete
null
Get Customer Addresses
Retrieve all active addresses for a customer, sorted with default address first.Id<'customers'>
The customer ID. If not provided, uses the authenticated user’s customer profile
Get Address
Retrieve a specific address by ID with full details.Id<'customerAddresses'>
required
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.Id<'customerAddresses'>
required
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
