增加“验证码登录”模式
This commit is contained in:
@@ -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')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user