diff --git a/apps/web-antdv-next/src/api/core/auth.ts b/apps/web-antdv-next/src/api/core/auth.ts index 6732416..f1a5d3c 100644 --- a/apps/web-antdv-next/src/api/core/auth.ts +++ b/apps/web-antdv-next/src/api/core/auth.ts @@ -10,6 +10,9 @@ export namespace AuthApi { /** 登录接口返回值 */ export interface LoginResult { accessToken: string; + wordpressAuth?: WordpressAuthResult['auth'] & { + user?: Record; + }; } export interface RefreshTokenResult { @@ -26,17 +29,6 @@ export namespace AuthApi { } } -interface ApiSuccessResponse { - code: number; - data: T; - msg: string; -} - -interface RawApiResponse { - data: ApiSuccessResponse; - status: number; -} - /** * 登录 */ @@ -72,36 +64,6 @@ export async function logoutApi() { ); } -/** - * WordPress 自动认证 - */ -export async function wordpressLoginApi() { - const response = await baseRequestClient.post< - RawApiResponse - >( - '/wordpress/auth/login', - {}, - { - withCredentials: true, - }, - ); - - return response.data.data; -} - -/** - * 清理 WordPress 授权态 - */ -export async function wordpressLogoutApi() { - return baseRequestClient.post( - '/wordpress/auth/logout', - {}, - { - withCredentials: true, - }, - ); -} - /** * 获取用户权限码 */ diff --git a/apps/web-antdv-next/src/store/auth.ts b/apps/web-antdv-next/src/store/auth.ts index 9899e8a..5925bec 100644 --- a/apps/web-antdv-next/src/store/auth.ts +++ b/apps/web-antdv-next/src/store/auth.ts @@ -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 {