import apiClient from './index'; export type AuthStatusResponse = { authEnabled: boolean; loggedIn: boolean; passwordSet?: boolean; passwordChangeable?: boolean; setupState: 'enabled' | 'password_retained' | 'no_password'; }; export const authApi = { async getStatus(): Promise { const { data } = await apiClient.get('/api/v1/auth/status'); return data; }, async updateSettings( authEnabled: boolean, password?: string, passwordConfirm?: string, currentPassword?: string ): Promise { const body: { authEnabled: boolean; password?: string; passwordConfirm?: string; currentPassword?: string; } = { authEnabled }; if (password !== undefined) { body.password = password; } if (passwordConfirm !== undefined) { body.passwordConfirm = passwordConfirm; } if (currentPassword !== undefined) { body.currentPassword = currentPassword; } const { data } = await apiClient.post('/api/v1/auth/settings', body); return data; }, async login(password: string, passwordConfirm?: string): Promise { const body: { password: string; passwordConfirm?: string } = { password }; if (passwordConfirm !== undefined) { body.passwordConfirm = passwordConfirm; } await apiClient.post('/api/v1/auth/login', body); }, async changePassword( currentPassword: string, newPassword: string, newPasswordConfirm: string ): Promise { await apiClient.post('/api/v1/auth/change-password', { currentPassword, newPassword, newPasswordConfirm, }); }, async logout(): Promise { await apiClient.post('/api/v1/auth/logout'); }, };