2026-05-02 13:02:57 +08:00

38 lines
1.3 KiB
TypeScript

import { apiRequest } from "@/shared/api/request";
import { API_ENDPOINTS, API_OPERATIONS, apiEndpointPath } from "@/shared/api/generated/endpoints";
import type { ChangePasswordPayload, LoginPayload, SessionDto } from "@/shared/api/types";
export function login(payload: LoginPayload): Promise<SessionDto> {
const endpoint = API_ENDPOINTS.login;
return apiRequest<SessionDto, LoginPayload>(apiEndpointPath(API_OPERATIONS.login), {
body: payload,
method: endpoint.method,
skipAuth: true
});
}
export function logout(): Promise<unknown> {
const endpoint = API_ENDPOINTS.logout;
return apiRequest(apiEndpointPath(API_OPERATIONS.logout), { method: endpoint.method, skipAuth: true });
}
export function refreshSession(): Promise<SessionDto> {
const endpoint = API_ENDPOINTS.refresh;
return apiRequest<SessionDto>(apiEndpointPath(API_OPERATIONS.refresh), {
method: endpoint.method,
skipAuth: true
});
}
export function getMe(): Promise<SessionDto> {
return apiRequest<SessionDto>(apiEndpointPath(API_OPERATIONS.me));
}
export function changePassword(payload: ChangePasswordPayload): Promise<unknown> {
const endpoint = API_ENDPOINTS.changePassword;
return apiRequest<unknown, ChangePasswordPayload>(apiEndpointPath(API_OPERATIONS.changePassword), {
body: payload,
method: endpoint.method
});
}