/** * Auth API — wraps /api/oa/auth/* and manages the stored Bearer token. */ import { http, setToken, clearToken, getToken } from './http' export interface OaSession { token: string id: number loginName: string displayName: string deptId: number | null title: string | null email: string | null roles: string[] } /** POST /auth/login -> stores the token and returns the session. */ export async function login(loginName: string, password: string): Promise { const session = await http.post('/auth/login', { loginName, password }) if (session?.token) setToken(session.token) return session } /** GET /auth/session -> resolves the current session from the stored token. */ export async function fetchSession(): Promise { return http.get('/auth/session') } /** POST /auth/logout -> clears the stored token regardless of server result. */ export async function logout(): Promise { try { await http.post('/auth/logout') } finally { clearToken() } } export { getToken, setToken, clearToken }