Files
ea-chatbot-lg/frontend/src/services/auth.ts
Yunxiao Xu 68c0985482 feat(auth): Complete OIDC security refactor and modernize test suite
- Refactored OIDC flow to implement PKCE, state/nonce validation, and BFF pattern.
- Centralized configuration in Settings class (DEV_MODE, FRONTEND_URL, OIDC_REDIRECT_URI).
- Updated auth routers to use conditional secure cookie flags based on DEV_MODE.
- Modernized and cleaned up test suite by removing legacy Streamlit tests.
- Fixed linting errors and unused imports across the backend.
2026-02-15 02:50:26 -08:00

53 lines
1.3 KiB
TypeScript

import api from "./api"
export interface AuthResponse {
access_token: string
token_type: string
}
export interface UserResponse {
id: string
email: string
display_name?: string
}
export const AuthService = {
async login(email: string, password: string): Promise<AuthResponse> {
const formData = new FormData()
formData.append("username", email)
formData.append("password", password)
const response = await api.post<AuthResponse>("/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<UserResponse> {
const response = await api.post<UserResponse>("/auth/register", {
email,
password,
})
return response.data
},
async getMe(): Promise<UserResponse> {
const response = await api.get<UserResponse>("/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")
},
}