fix: 修复双Token自动刷新链路
All checks were successful
Build and Deploy TenantUI / build-and-deploy (push) Successful in 53s
All checks were successful
Build and Deploy TenantUI / build-and-deploy (push) Successful in 53s
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import type { RequestClientConfig } from '@vben/request';
|
||||
|
||||
import { baseRequestClient, requestClient } from '#/api/request';
|
||||
|
||||
export namespace AuthApi {
|
||||
@@ -53,10 +55,14 @@ export async function loginApi(data: AuthApi.LoginParams) {
|
||||
/**
|
||||
* 刷新accessToken
|
||||
*/
|
||||
export async function refreshTokenApi(data: AuthApi.RefreshTokenParams) {
|
||||
export async function refreshTokenApi(
|
||||
data: AuthApi.RefreshTokenParams,
|
||||
config?: RequestClientConfig,
|
||||
) {
|
||||
return baseRequestClient.post<AuthApi.ApiResponse<AuthApi.LoginResult>>(
|
||||
'/auth/refresh',
|
||||
data,
|
||||
config,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -117,11 +117,27 @@ function createRequestClient(baseURL: string, options?: RequestClientOptions) {
|
||||
throw new Error('refresh token is required');
|
||||
}
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
'Accept-Language': preferences.app.locale,
|
||||
};
|
||||
const { tenantCode, tenantId } = resolveTenantHeaderPayload();
|
||||
if (tenantCode) {
|
||||
headers[TENANT_CODE_HEADER_KEY] = tenantCode;
|
||||
} else if (tenantId) {
|
||||
headers[TENANT_ID_HEADER_KEY] = tenantId;
|
||||
}
|
||||
|
||||
const resp = await refreshTokenApi({
|
||||
refreshToken: currentRefreshToken,
|
||||
}, {
|
||||
headers,
|
||||
});
|
||||
|
||||
const tokenData = resp?.data;
|
||||
const responseBody = (resp as any)?.data ?? resp;
|
||||
const tokenData =
|
||||
responseBody?.accessToken || responseBody?.refreshToken
|
||||
? responseBody
|
||||
: responseBody?.data;
|
||||
const newAccessToken = tokenData?.accessToken;
|
||||
const newRefreshToken = tokenData?.refreshToken ?? currentRefreshToken;
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ async function initApplication() {
|
||||
app: {
|
||||
accessMode: 'backend',
|
||||
defaultHomePath: '/dashboard/console',
|
||||
enableRefreshToken: true,
|
||||
loginExpiredMode: 'modal',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ export const overridesPreferences = defineOverridesPreferences({
|
||||
app: {
|
||||
accessMode: 'backend',
|
||||
defaultHomePath: '/dashboard/console',
|
||||
enableRefreshToken: true,
|
||||
loginExpiredMode: 'modal',
|
||||
name: import.meta.env.VITE_APP_TITLE,
|
||||
},
|
||||
theme: {
|
||||
|
||||
Reference in New Issue
Block a user