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 退 * @description 退
*/ */
export const apiUserLogout = async () => { export const apiUserLogout = async (token: string) => {
const res: FetchResponse<string> = await clientHttp.get('/queyueapi/user/user/logout'); fetch('/queyueapi/user/user/logout', {
return res; headers: {
Authorization: token,
},
method: 'GET',
});
}; };
/** /**

@ -1,5 +1,5 @@
import { produce } from 'immer'; import { produce } from 'immer';
import { setCookie, destroyCookie } from 'nookies'; import { setCookie, parseCookies, destroyCookie } from 'nookies';
import { create } from 'zustand'; import { create } from 'zustand';
import { devtools, persist, createJSONStorage } from 'zustand/middleware'; import { devtools, persist, createJSONStorage } from 'zustand/middleware';
@ -22,8 +22,6 @@ interface UserState {
setUserInfo: (parmas: UserInfo) => void; setUserInfo: (parmas: UserInfo) => void;
/** 用户登录 */ /** 用户登录 */
userLogin: (params: TRequestLogin) => Promise<FetchResponse<string>>; userLogin: (params: TRequestLogin) => Promise<FetchResponse<string>>;
/** 登出 */
userLogout: () => void;
/** 获取用户信息 */ /** 获取用户信息 */
getUserInfo: () => Promise<FetchResponse<UserInfo>>; getUserInfo: () => Promise<FetchResponse<UserInfo>>;
} }
@ -87,11 +85,6 @@ const useUserStore = create<UserState>()(
} }
return result; return result;
}, },
userLogout: async () => {
apiUserLogout();
setUserInfo(initialUserInfo);
destroyCookie(null, 'token');
},
getUserInfo, getUserInfo,
}; };
}, },

@ -1,12 +1,13 @@
import { destroyCookie } from 'nookies'; import { parseCookies, destroyCookie } from 'nookies';
import { apiUserLogout } from '@/services'; import { apiUserLogout } from '@/services';
const logout = () => { const logout = () => {
apiUserLogout(); const { token } = parseCookies();
localStorage.clear();
destroyCookie(null, 'token'); destroyCookie(null, 'token');
window.location.reload(); localStorage.clear();
apiUserLogout(token);
window.location.replace('/');
}; };
export default logout; export default logout;

Loading…
Cancel
Save