admin / apps /web-antd /src /api /core /auth.ts
hanbinsite's picture
chore: HuggingFace deploy 2026-05-19 10:37
dc649b1
Raw History Blame Contribute Delete
1.22 kB
import { baseRequestClient, requestClient } from '#/api/request';
export namespace AuthApi {
/** 登录接口参数 */
export interface LoginParams {
password?: string;
username?: string;
}
/** 登录接口返回值 */
export interface LoginResult {
accessToken: string;
}
export interface RefreshTokenResult {
data: string;
status: number;
}
}
/**
* 登录 → POST /admin/auth/login
*/
export async function loginApi(data: AuthApi.LoginParams) {
return requestClient.post<AuthApi.LoginResult>('/auth/login', data);
}
/**
* 刷新 token → 后端暂未实现,直接返回空让前端走重新登录逻辑
*/
export async function refreshTokenApi(): Promise<AuthApi.RefreshTokenResult> {
// Backend does not implement /auth/refresh yet.
// Return a rejected promise so the interceptor falls through to re-authenticate.
throw new Error('refresh_not_supported');
}
/**
* 退出登录 → POST /admin/auth/logout
*/
export async function logoutApi() {
return baseRequestClient.post('/auth/logout');
}
/**
* 获取用户权限码 → GET /admin/auth/codes
*/
export async function getAccessCodesApi() {
return requestClient.get<string[]>('/auth/codes');
}