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 {
|
export interface LoginResult {
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
|
wordpressAuth?: WordpressAuthResult['auth'] & {
|
||||||
|
user?: Record<string, any>;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RefreshTokenResult {
|
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 { notification } from 'antdv-next';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
import {
|
import { getAccessCodesApi, getUserInfoApi, loginApi, logoutApi } from '#/api';
|
||||||
getAccessCodesApi,
|
|
||||||
getUserInfoApi,
|
|
||||||
loginApi,
|
|
||||||
logoutApi,
|
|
||||||
wordpressLoginApi,
|
|
||||||
wordpressLogoutApi,
|
|
||||||
} from '#/api';
|
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', () => {
|
export const useAuthStore = defineStore('auth', () => {
|
||||||
@ -111,7 +104,7 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
let userInfo: null | UserInfo = null;
|
let userInfo: null | UserInfo = null;
|
||||||
try {
|
try {
|
||||||
loginLoading.value = true;
|
loginLoading.value = true;
|
||||||
const { accessToken } = await loginApi(params);
|
const { accessToken, wordpressAuth } = await loginApi(params);
|
||||||
|
|
||||||
// 如果成功获取到 accessToken
|
// 如果成功获取到 accessToken
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
@ -122,16 +115,12 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
fetchUserInfo(),
|
fetchUserInfo(),
|
||||||
getAccessCodesApi(),
|
getAccessCodesApi(),
|
||||||
]);
|
]);
|
||||||
const wordpressAuth = await wordpressLoginApi();
|
|
||||||
|
|
||||||
userInfo = fetchUserInfoResult;
|
userInfo = fetchUserInfoResult;
|
||||||
|
|
||||||
userStore.setUserInfo(userInfo);
|
userStore.setUserInfo(userInfo);
|
||||||
accessStore.setAccessCodes(accessCodes);
|
accessStore.setAccessCodes(accessCodes);
|
||||||
accessStore.setWordpressAuth({
|
accessStore.setWordpressAuth(wordpressAuth || null);
|
||||||
...wordpressAuth.auth,
|
|
||||||
user: wordpressAuth.user,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (accessStore.loginExpired) {
|
if (accessStore.loginExpired) {
|
||||||
accessStore.setLoginExpired(false);
|
accessStore.setLoginExpired(false);
|
||||||
@ -158,7 +147,6 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
userStore.setUserInfo(null);
|
userStore.setUserInfo(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await wordpressLogoutApi();
|
|
||||||
await logoutApi();
|
await logoutApi();
|
||||||
} catch {
|
} catch {
|
||||||
// 不做任何处理
|
// 不做任何处理
|
||||||
@ -180,12 +168,6 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
if (isLoggingOut.value) return; // 正在登出中, 说明已进入循环, 直接返回.
|
if (isLoggingOut.value) return; // 正在登出中, 说明已进入循环, 直接返回.
|
||||||
isLoggingOut.value = true; // 设置 标识
|
isLoggingOut.value = true; // 设置 标识
|
||||||
|
|
||||||
try {
|
|
||||||
await wordpressLogoutApi();
|
|
||||||
} catch {
|
|
||||||
// 不做任何处理
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await logoutApi();
|
await logoutApi();
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user