const AUTH = { async me() { const res = await fetch("/api/auth/me", { credentials: "include" }); if (!res.ok) return null; return res.json(); }, async login(username, password) { const res = await fetch("/api/auth/login", { method: "POST", credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password }), }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.detail || "登录失败"); return data; }, async logout() { await fetch("/api/auth/logout", { method: "POST", credentials: "include" }); }, async changeCredentials(payload) { const res = await fetch("/api/auth/change-credentials", { method: "POST", credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.detail || "修改失败"); return data; }, };