Files
aplp.frontend.web/src/features/auth/api/authApi.ts
T

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2026-08-11 21:09:32 +07:00
import client from '@/api/client';
import type { ApiListResponse, ApiResponse } from '@/types/api';
import type { AuthUser, LoginCredentials, LoginResponse, RefreshResponse } from '../types';
/**
* Endpoint constants live here (not scattered in components).
* Contract per backend `aplp.backend.spring` (candidate, confirm at Phase 0).
*/
const ENDPOINTS = {
login: '/auth/login',
logout: '/auth/logout',
refresh: '/auth/refresh',
me: '/auth/me',
} as const;
export const authApi = {
async login(credentials: LoginCredentials): Promise<LoginResponse> {
const { data } = await client.post<ApiResponse<LoginResponse>>(ENDPOINTS.login, credentials);
return data.data;
},
async logout(): Promise<void> {
await client.post(ENDPOINTS.logout);
},
async refresh(): Promise<RefreshResponse> {
const { data } = await client.post<ApiResponse<RefreshResponse>>(ENDPOINTS.refresh);
return data.data;
},
async getMe(): Promise<AuthUser> {
const { data } = await client.get<ApiResponse<AuthUser>>(ENDPOINTS.me);
return data.data;
},
async listUsers(): Promise<ApiListResponse<AuthUser>> {
const { data } = await client.get<ApiListResponse<AuthUser>>('/users');
return data;
},
};