Files
lotteryFront/src/api/player-auth.ts

58 lines
1.6 KiB
TypeScript

import { lotteryRequest } from "@/lib/lottery-http";
export type PlayerAuthCaptchaResponse = {
captcha_key: string;
image_base64: string;
};
export type PlayerAuthLoginPayload = {
site_code?: string;
username: string;
password: string;
captcha_key: string;
captcha_code: string;
};
export type PlayerAuthLoginData = {
access_token: string;
expires_in: number;
token_type: string;
player: {
id: number;
site_code: string;
username: string | null;
nickname: string | null;
funding_mode: string;
auth_source: string;
};
};
export type PlayerPasswordUpdatePayload = {
current_password: string;
password: string;
password_confirmation: string;
};
/** `GET /api/v1/player/auth/captcha`(公开) */
export function getPlayerAuthCaptcha(): Promise<PlayerAuthCaptchaResponse> {
return lotteryRequest.get<PlayerAuthCaptchaResponse>(`/player/auth/captcha`, {
skipGlobalServerError: true,
});
}
/** `POST /api/v1/player/auth/login`(公开) */
export function postPlayerAuthLogin(body: PlayerAuthLoginPayload): Promise<PlayerAuthLoginData> {
const siteCode = process.env.NEXT_PUBLIC_PLAYER_SITE_CODE?.trim();
return lotteryRequest.post<PlayerAuthLoginData>(`/player/auth/login`, {
...(siteCode ? { site_code: siteCode } : {}),
...body,
});
}
/** `PUT /api/v1/player/password`(仅彩票端账号密码玩家) */
export function putPlayerPassword(
body: PlayerPasswordUpdatePayload,
): Promise<{ password_changed: boolean }> {
return lotteryRequest.put<{ password_changed: boolean }>(`/player/password`, body);
}