Add graphic captcha before user SMS login

This commit is contained in:
2026-07-09 12:09:10 +08:00
parent 0e2706a4f4
commit 34d6dd01c7
10 changed files with 234 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
import type { ApiResponse, ChatMessage, ChatSession, LoginResult, UserProfile } from "../types/api";
import type { ApiResponse, CaptchaResult, ChatMessage, ChatSession, LoginResult, UserProfile } from "../types/api";
const API_BASE = import.meta.env.VITE_API_BASE_URL ?? "http://127.0.0.1:8100/api";
const TOKEN_KEY = "ai-kb-user-token";
@@ -31,7 +31,9 @@ async function request<T>(path: string, init: RequestInit = {}): Promise<T> {
}
export const api = {
sendSms: (phone: string) => request<null>("/auth/sms/send", { method: "POST", body: JSON.stringify({ phone }) }),
captcha: () => request<CaptchaResult>("/auth/captcha"),
sendSms: (phone: string, captchaId: string, captchaCode: string) =>
request<null>("/auth/sms/send", { method: "POST", body: JSON.stringify({ phone, captchaId, captchaCode }) }),
login: (phone: string, code: string) =>
request<LoginResult>("/auth/login", { method: "POST", body: JSON.stringify({ phone, code }) }),
logout: () => request<null>("/auth/logout", { method: "POST", body: JSON.stringify({}) }),