import api from "./api" import type { Theme } from "@/components/theme-provider" export interface AuthResponse { access_token: string token_type: string } export interface UserResponse { id: string email: string display_name?: string theme_preference: Theme } export const AuthService = { async login(email: string, password: string): Promise { const formData = new FormData() formData.append("username", email) formData.append("password", password) const response = await api.post("/auth/login", formData) return response.data }, async loginWithOIDC() { const response = await api.get<{ url: string }>("/auth/oidc/login") if (response.data.url) { window.location.href = response.data.url } }, async register(email: string, password: string): Promise { const response = await api.post("/auth/register", { email, password, }) return response.data }, async getMe(): Promise { const response = await api.get("/auth/me") // Double check that we got JSON and not an HTML fallback const contentType = response.headers["content-type"] if (contentType && !contentType.includes("application/json")) { throw new Error("Invalid response from server") } return response.data }, async logout() { await api.post("/auth/logout") }, async refreshSession(): Promise { const response = await api.post("/auth/refresh") return response.data }, async updateTheme(theme: Theme): Promise { const response = await api.patch("/auth/theme", { theme }) return response.data }, }