import { apiRequest, setToken, clearToken } from './client'

export async function login(email, password) {
  const data = await apiRequest('/auth/login', {
    method: 'POST',
    body: { email, password },
  })
  setToken(data.access_token)
  return data
}

export async function fetchMe() {
  return apiRequest('/auth/me')
}

export function logout() {
  clearToken()
  window.dispatchEvent(new CustomEvent('auth:logout'))
}
