35 lines
990 B
TypeScript
35 lines
990 B
TypeScript
import { apiRequest } from '@/lib/api'
|
|
|
|
import type { CurrentUser } from './types'
|
|
|
|
export async function getCurrentUser() {
|
|
return apiRequest<CurrentUser>('/accounts/auth/me')
|
|
}
|
|
|
|
export function updateCurrentUser(payload: { display_name?: string; email?: string }) {
|
|
return apiRequest<CurrentUser>('/accounts/auth/me', {
|
|
method: 'PATCH',
|
|
body: JSON.stringify(payload)
|
|
})
|
|
}
|
|
|
|
export function changePassword(currentPassword: string, newPassword: string) {
|
|
return apiRequest<{ status: string }>('/accounts/auth/change-password', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ current_password: currentPassword, new_password: newPassword })
|
|
})
|
|
}
|
|
|
|
export async function login(username: string, password: string) {
|
|
return apiRequest<CurrentUser>('/accounts/auth/login', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ username, password })
|
|
})
|
|
}
|
|
|
|
export async function logout() {
|
|
await apiRequest<{ status: string }>('/accounts/auth/logout', {
|
|
method: 'POST'
|
|
})
|
|
}
|