import { api } from '$lib/api/httpClient'; // 通常不需要 .ts 后缀 import type { AuthResponse, LoginPayload } from '$lib/types/auth'; import { ApiError } from '$lib/types/api.ts'; export const authService = { /** * 登录流程 */ login: async (payload: LoginPayload): Promise => { // 1. 调用登录接口 const response = await api.post('/auth/login', payload); if (response.code !== 200 || !response.data) { throw new ApiError(response); } return response.data; }, /** * 登出流程 */ logout: async () => { try { // Optionally call the backend logout endpoint await api.post('/auth/logout', {}); } catch (error) { // Even if the backend call fails, we still want to clear local state console.warn('Logout API call failed:', error); } } };