Appearance
useProfileApi Composable ​
File Information ​
- Path:
app/composables/api/useProfileApi.ts - Purpose: User profile operations API
- Category: User API Composable
Overview ​
The useProfileApi composable provides functionality for updating user profile information and changing user password.
Functions ​
updateUserProfile ​
Updates user profile information.
Signature:
typescript
updateUserProfile(body: any): Promise<any>Parameters:
body: any- Profile update data (can be FormData for file uploads or plain object)
Returns:
Promise<any>- Update response
API Endpoint: POST /digital/instance/update-user
Special Handling:
- If
bodyis aFormDatainstance, it's sent directly (for file uploads) - Otherwise, body is converted to object
Usage:
typescript
const { updateUserProfile } = useProfileApi()
// Update with plain object
await updateUserProfile({
name: 'New Name',
email: '[email protected]'
})
// Update with FormData (for avatar upload)
const formData = new FormData()
formData.append('name', 'New Name')
formData.append('avatar', file)
await updateUserProfile(formData)changeUserPassword ​
Changes user password.
Signature:
typescript
changeUserPassword(body: any): Promise<any>Parameters:
body: any- Password change data (current_password, new_password, etc.)
Returns:
Promise<any>- Change password response
API Endpoint: POST /auth-change-password
Usage:
typescript
const { changeUserPassword } = useProfileApi()
await changeUserPassword({
current_password: 'oldPassword',
new_password: 'newPassword',
new_password_confirmation: 'newPassword'
})Error Handling ​
All functions include error logging:
typescript
catch (error: any) {
console.error("[ProfileAPI] {functionName} - Error:", error)
throw error
}Integration with API Client ​
The composable uses the global $api client:
typescript
const { $api } = useNuxtApp()Use Cases ​
Update Profile ​
typescript
const { updateUserProfile } = useProfileApi()
const updateProfile = async (profileData: any) => {
try {
await updateUserProfile(profileData)
snackbar.showSuccess('Profile updated successfully')
} catch (error) {
snackbar.showError('Failed to update profile')
}
}Upload Avatar ​
typescript
const { updateUserProfile } = useProfileApi()
const uploadAvatar = async (file: File) => {
const formData = new FormData()
formData.append('avatar', file)
formData.append('name', user.name)
try {
await updateUserProfile(formData)
snackbar.showSuccess('Avatar updated successfully')
} catch (error) {
snackbar.showError('Failed to upload avatar')
}
}Change Password ​
typescript
const { changeUserPassword } = useProfileApi()
const changePassword = async (currentPassword: string, newPassword: string) => {
try {
await changeUserPassword({
current_password: currentPassword,
new_password: newPassword,
new_password_confirmation: newPassword
})
snackbar.showSuccess('Password changed successfully')
} catch (error) {
snackbar.showError('Failed to change password')
}
}Related Documentation ​
- Profile Feature - Profile feature documentation
- API Client - API client configuration