增加“验证码登录”模式

This commit is contained in:
yml2213
2026-08-20 14:46:53 +08:00
parent 757eee9742
commit 555a7d43a7
4 changed files with 352 additions and 45 deletions
+24
View File
@@ -64,6 +64,30 @@ export function loginWorker(payload: { username: string; password: string }) {
})
}
function buildWorkerDevicePayload() {
const userAgent = navigator.userAgent
const isMobile = /Android|iPhone|iPad|iPod|Mobile/i.test(userAgent)
return {
deviceId: getWorkerDeviceId(),
deviceType: isMobile ? 'mobile' : 'pc',
deviceName: isMobile ? '手机浏览器' : 'PC 浏览器',
}
}
export function sendWorkerLoginSmsCode(payload: { phone: string }) {
return apiPost<{ sent: boolean; expiresInSeconds: number; provider: string }>(
'/api/v1/worker/auth/login/sms-code',
payload,
)
}
export function loginWorkerBySmsCode(payload: { phone: string; code: string }) {
return apiPost<WorkerLoginResponse>('/api/v1/worker/auth/login/sms', {
...payload,
...buildWorkerDevicePayload(),
})
}
export function fetchWorkerSessions() {
return apiGet<{ maxDevices: number; items: WorkerSessionDevice[] }>('/api/v1/worker/auth/devices')
}