| 1 | import { apiClient } from "./client"; |
| 2 | import { AuthResponse, LoginRequest, RegisterRequest } from "./types"; |
| 3 | |
| 4 | export const authApi = { |
| 5 | async login(data: LoginRequest): Promise<AuthResponse> { |
| 6 | const response = await apiClient.post("/auth/login", data); |
| 7 | return response.data.data; |
| 8 | }, |
| 9 | |
| 10 | async register(data: RegisterRequest): Promise<AuthResponse> { |
| 11 | const response = await apiClient.post("/auth/register", data); |
| 12 | return response.data.data; |
| 13 | }, |
| 14 | |
| 15 | async getCurrentUser(): Promise<AuthResponse> { |
| 16 | const response = await apiClient.get("/auth/me"); |
| 17 | const data = response.data.data; |
| 18 | |
| 19 | if (data.token && typeof window !== "undefined") { |
| 20 | localStorage.setItem("token", data.token); |
| 21 | } |
| 22 | |
| 23 | return data; |
| 24 | }, |
| 25 | }; |