diff --git a/src/services/client/user.ts b/src/services/client/user.ts index 2b2a98e..bf36980 100644 --- a/src/services/client/user.ts +++ b/src/services/client/user.ts @@ -48,9 +48,13 @@ export const apiAutoLogin = async (params: { deviceId: string; deviceBrand?: str /** * @description 退出登录 */ -export const apiUserLogout = async () => { - const res: FetchResponse = await clientHttp.get('/queyueapi/user/user/logout'); - return res; +export const apiUserLogout = async (token: string) => { + fetch('/queyueapi/user/user/logout', { + headers: { + Authorization: token, + }, + method: 'GET', + }); }; /** diff --git a/src/store/user.ts b/src/store/user.ts index 0b3fe0f..330880d 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -1,5 +1,5 @@ import { produce } from 'immer'; -import { setCookie, destroyCookie } from 'nookies'; +import { setCookie, parseCookies, destroyCookie } from 'nookies'; import { create } from 'zustand'; import { devtools, persist, createJSONStorage } from 'zustand/middleware'; @@ -22,8 +22,6 @@ interface UserState { setUserInfo: (parmas: UserInfo) => void; /** 用户登录 */ userLogin: (params: TRequestLogin) => Promise>; - /** 登出 */ - userLogout: () => void; /** 获取用户信息 */ getUserInfo: () => Promise>; } @@ -87,11 +85,6 @@ const useUserStore = create()( } return result; }, - userLogout: async () => { - apiUserLogout(); - setUserInfo(initialUserInfo); - destroyCookie(null, 'token'); - }, getUserInfo, }; }, diff --git a/src/utils/logout.ts b/src/utils/logout.ts index c7c6099..35ad1ff 100644 --- a/src/utils/logout.ts +++ b/src/utils/logout.ts @@ -1,12 +1,13 @@ -import { destroyCookie } from 'nookies'; +import { parseCookies, destroyCookie } from 'nookies'; import { apiUserLogout } from '@/services'; const logout = () => { - apiUserLogout(); - localStorage.clear(); + const { token } = parseCookies(); destroyCookie(null, 'token'); - window.location.reload(); + localStorage.clear(); + apiUserLogout(token); + window.location.replace('/'); }; export default logout;