dify_admin/web/src/api/auth/index.ts

45 lines
1.1 KiB
TypeScript

import { request } from '../../axios/service'
import type { LoginParams, RegisterParams, LoginForm } from '@/api/auth/types'
export const login = (data: { username: string; password: string }) =>
request<{ access_token: string }>({
method: 'POST',
url: '/api/auth/login',
data: data,
headers: {
'Content-Type': 'application/json'
}
})
export const register = (formData: FormData) =>
request<{ user_id: string }>({
method: 'POST',
url: '/api/auth/register',
data: formData,
headers: {
'Content-Type': 'multipart/form-data'
}
})
export const getPublicKey = async (): Promise<string> => {
try {
const res = await request<{ data: string }>({
method: 'GET',
url: '/api/auth/public-key'
})
if (!res.data) {
throw new Error('公钥获取失败')
}
return res.data
} catch (error) {
console.error('获取公钥失败:', error)
throw new Error('获取公钥失败: ' + (error instanceof Error ? error.message : String(error)))
}
}
export const refreshToken = () =>
request<{ access_token: string }>({
method: 'POST',
url: '/api/auth/refresh'
})