initial
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user