mirror of
https://github.com/KwiTsukasa/kt-template-admin.git
synced 2026-05-27 16:35:47 +08:00
fix(admin): 移除前端WordPress认证调用
This commit is contained in:
parent
88310e0ee1
commit
4b4e6de601
@ -10,6 +10,9 @@ export namespace AuthApi {
|
||||
/** 登录接口返回值 */
|
||||
export interface LoginResult {
|
||||
accessToken: string;
|
||||
wordpressAuth?: WordpressAuthResult['auth'] & {
|
||||
user?: Record<string, any>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface RefreshTokenResult {
|
||||
@ -26,17 +29,6 @@ export namespace AuthApi {
|
||||
}
|
||||
}
|
||||
|
||||
interface ApiSuccessResponse<T> {
|
||||
code: number;
|
||||
data: T;
|
||||
msg: string;
|
||||
}
|
||||
|
||||
interface RawApiResponse<T> {
|
||||
data: ApiSuccessResponse<T>;
|
||||
status: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
@ -72,36 +64,6 @@ export async function logoutApi() {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* WordPress 自动认证
|
||||
*/
|
||||
export async function wordpressLoginApi() {
|
||||
const response = await baseRequestClient.post<
|
||||
RawApiResponse<AuthApi.WordpressAuthResult>
|
||||
>(
|
||||
'/wordpress/auth/login',
|
||||
{},
|
||||
{
|
||||
withCredentials: true,
|
||||
},
|
||||
);
|
||||
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理 WordPress 授权态
|
||||
*/
|
||||
export async function wordpressLogoutApi() {
|
||||
return baseRequestClient.post(
|
||||
'/wordpress/auth/logout',
|
||||
{},
|
||||
{
|
||||
withCredentials: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户权限码
|
||||
*/
|
||||
|
||||
@ -10,14 +10,7 @@ import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores';
|
||||
import { notification } from 'antdv-next';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
import {
|
||||
getAccessCodesApi,
|
||||
getUserInfoApi,
|
||||
loginApi,
|
||||
logoutApi,
|
||||
wordpressLoginApi,
|
||||
wordpressLogoutApi,
|
||||
} from '#/api';
|
||||
import { getAccessCodesApi, getUserInfoApi, loginApi, logoutApi } from '#/api';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
@ -111,7 +104,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
let userInfo: null | UserInfo = null;
|
||||
try {
|
||||
loginLoading.value = true;
|
||||
const { accessToken } = await loginApi(params);
|
||||
const { accessToken, wordpressAuth } = await loginApi(params);
|
||||
|
||||
// 如果成功获取到 accessToken
|
||||
if (accessToken) {
|
||||
@ -122,16 +115,12 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
fetchUserInfo(),
|
||||
getAccessCodesApi(),
|
||||
]);
|
||||
const wordpressAuth = await wordpressLoginApi();
|
||||
|
||||
userInfo = fetchUserInfoResult;
|
||||
|
||||
userStore.setUserInfo(userInfo);
|
||||
accessStore.setAccessCodes(accessCodes);
|
||||
accessStore.setWordpressAuth({
|
||||
...wordpressAuth.auth,
|
||||
user: wordpressAuth.user,
|
||||
});
|
||||
accessStore.setWordpressAuth(wordpressAuth || null);
|
||||
|
||||
if (accessStore.loginExpired) {
|
||||
accessStore.setLoginExpired(false);
|
||||
@ -158,7 +147,6 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
userStore.setUserInfo(null);
|
||||
|
||||
try {
|
||||
await wordpressLogoutApi();
|
||||
await logoutApi();
|
||||
} catch {
|
||||
// 不做任何处理
|
||||
@ -180,12 +168,6 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
if (isLoggingOut.value) return; // 正在登出中, 说明已进入循环, 直接返回.
|
||||
isLoggingOut.value = true; // 设置 标识
|
||||
|
||||
try {
|
||||
await wordpressLogoutApi();
|
||||
} catch {
|
||||
// 不做任何处理
|
||||
}
|
||||
|
||||
try {
|
||||
await logoutApi();
|
||||
} catch {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user