Files
sub2api/frontend/src/api/user.ts

55 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-12-18 13:50:39 +08:00
/**
* User API endpoints
* Handles user profile management and password changes
*/
import { apiClient } from './client'
import type { User, ChangePasswordRequest } from '@/types'
2025-12-18 13:50:39 +08:00
/**
* Get current user profile
* @returns User profile data
*/
export async function getProfile(): Promise<User> {
const { data } = await apiClient.get<User>('/user/profile')
return data
}
/**
* Update current user profile
* @param profile - Profile data to update
* @returns Updated user profile data
*/
export async function updateProfile(profile: {
username?: string
}): Promise<User> {
const { data } = await apiClient.put<User>('/user', profile)
return data
2025-12-18 13:50:39 +08:00
}
/**
* Change current user password
* @param passwords - Old and new password
* @returns Success message
*/
export async function changePassword(
oldPassword: string,
newPassword: string
): Promise<{ message: string }> {
const payload: ChangePasswordRequest = {
old_password: oldPassword,
new_password: newPassword
}
2025-12-18 13:50:39 +08:00
const { data } = await apiClient.put<{ message: string }>('/user/password', payload)
return data
2025-12-18 13:50:39 +08:00
}
export const userAPI = {
getProfile,
updateProfile,
changePassword
}
2025-12-18 13:50:39 +08:00
export default userAPI