gemercheung 1 vuosi sitten
vanhempi
commit
977846d138
2 muutettua tiedostoa jossa 10 lisäystä ja 2 poistoa
  1. 7 0
      src/request/index.ts
  2. 3 2
      src/store/user.ts

+ 7 - 0
src/request/index.ts

@@ -92,6 +92,13 @@ export const loginFetch = (props: LoginProps) =>
     body: JSON.stringify(props),
   });
 
+  export const loginOutFetch = () =>
+    sendFetch<{ user: UserInfo; token: string }>(URL.logout, {
+      method: "post",
+      body: JSON.stringify({}),
+    });
+  
+
 export const userInfoFetch = () =>
   sendFetch<UserInfo>(URL.getUserInfo, { method: "post" });
 

+ 3 - 2
src/store/user.ts

@@ -1,4 +1,4 @@
-import { LoginProps, loginFetch, userInfoFetch } from "@/request";
+import { LoginProps, loginFetch, userInfoFetch, loginOutFetch } from "@/request";
 import { errorHook, gHeaders } from "@/request/state";
 import { UserInfo } from "@/request/type";
 import { encodePwd } from "@/util";
@@ -25,7 +25,8 @@ export const login = async (props: LoginProps) => {
   await getUserInfo();
 };
 
-export const logout = () => {
+export const logout = async () => {
+  await loginOutFetch();
   localStorage.removeItem("token");
   userStatus.value = UserStatus.NOT_LOGIN;
 };