feat: 新增 JWT 刷新模式,支持因访问令牌过期而失败的请求重试

This commit is contained in:
ray
2024-11-14 18:32:23 +08:00
parent 0902e2320f
commit ad9dd5e1d1
5 changed files with 127 additions and 54 deletions

View File

@@ -3,7 +3,7 @@ import request from "@/utils/request";
const AUTH_BASE_URL = "/api/v1/auth";
const AuthAPI = {
/** 登录 接口*/
/** 登录接口*/
login(data: LoginData) {
const formData = new FormData();
formData.append("username", data.username);
@@ -20,7 +20,7 @@ const AuthAPI = {
});
},
/** 刷新token 接口*/
/** 刷新 token 接口*/
refreshToken(refreshToken: string) {
return request<any, LoginResult>({
url: `${AUTH_BASE_URL}/refresh-token`,
@@ -32,7 +32,7 @@ const AuthAPI = {
});
},
/** 注销 接口*/
/** 注销接口*/
logout() {
return request({
url: `${AUTH_BASE_URL}/logout`,
@@ -40,7 +40,7 @@ const AuthAPI = {
});
},
/** 获取验证码 接口*/
/** 获取验证码接口*/
getCaptcha() {
return request<any, CaptchaResult>({
url: `${AUTH_BASE_URL}/captcha`,
@@ -65,14 +65,14 @@ export interface LoginData {
/** 登录响应 */
export interface LoginResult {
/** 访问token */
accessToken?: string;
/** 过期时间(单位:毫秒) */
expires?: number;
/** 刷新token */
refreshToken?: string;
/** token 类型 */
tokenType?: string;
/** 访问令牌 */
accessToken: string;
/** 刷新令牌 */
refreshToken: string;
/** 令牌类型 */
tokenType: string;
/** 过期时间(秒) */
expiresIn: number;
}
/** 验证码响应 */