fix(logout): 登出清除 cookie

mack-mac
mackt 7 months ago
parent ee7d9a898d
commit c70e247458

@ -48,9 +48,13 @@ export const apiAutoLogin = async (params: { deviceId: string; deviceBrand?: str
/**
* @description 退
*/
export const apiUserLogout = async () => {
const res: FetchResponse<string> = 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',
});
};
/**

@ -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<FetchResponse<string>>;
/** 登出 */
userLogout: () => void;
/** 获取用户信息 */
getUserInfo: () => Promise<FetchResponse<UserInfo>>;
}
@ -87,11 +85,6 @@ const useUserStore = create<UserState>()(
}
return result;
},
userLogout: async () => {
apiUserLogout();
setUserInfo(initialUserInfo);
destroyCookie(null, 'token');
},
getUserInfo,
};
},

@ -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;

Loading…
Cancel
Save