Bladeren bron

fix: 删除本地存储token操作;

Before 10 maanden geleden
bovenliggende
commit
8cd70e350e

+ 1 - 7
src/app/[locale]/(TabBar)/(ordinary)/sports/page.tsx

@@ -1,5 +1,4 @@
 "use client";
-import { useGlobalStore } from "@/stores";
 import { useTranslations } from "next-intl";
 import { FC } from "react";
 import "./page.scss";
@@ -8,13 +7,8 @@ interface Props {}
 
 const Sports: FC<Props> = () => {
     const t = useTranslations("ProfilePage");
-    const { token, userInfo, setUserInfo } = useGlobalStore();
 
-    return (
-        <div className="sports-box">
-            to by continued
-        </div>
-    );
+    return <div className="sports-box">to by continued</div>;
 };
 
 export default Sports;

+ 3 - 4
src/app/[locale]/(enter)/components/FromCom/index-copy.tsx

@@ -2,6 +2,7 @@
 import ButtonOwn from "@/components/ButtonOwn";
 import { Link, useRouter } from "@/i18n";
 import { useGlobalStore } from "@/stores";
+import { setCookies } from "@/utils/Cookies";
 import { Toast } from "antd-mobile";
 import clsx from "clsx";
 import { useTranslations } from "next-intl";
@@ -40,7 +41,7 @@ const FromCom: FC<PropsWithChildren<FromComProps>> = ({ type = "login", msgError
     let [pwdVisible, setPwdVisible] = useState(false);
     const searchParams = useSearchParams();
     const router = useRouter();
-    const { setUserInfo, setToken } = useGlobalStore();
+    const { setUserInfo } = useGlobalStore();
     const [loginFormStatus, setLoginFormStatus] = useState<{ success?: boolean; message?: string }>(
         {}
     );
@@ -48,10 +49,8 @@ const FromCom: FC<PropsWithChildren<FromComProps>> = ({ type = "login", msgError
     const formAction = async (formData: FormData) => {
         Toast.show({ icon: "loading", duration: 3000, maskClickable: false });
         const result = await loginAction(formData);
-        // todo token存放位置在本地, 优化目标: 要做服务端渲染应该获取cookie里面的token
         setUserInfo(result.user);
-        setToken(result.token!);
-        console.log(`🚀🚀🚀🚀🚀-> in index.tsx on 54`, result);
+        setCookies("Token", result.token!);
         setLoginFormStatus(result);
         Toast.clear();
         if (result.success) {

+ 2 - 3
src/components/Card/Card.tsx

@@ -2,8 +2,8 @@
 import { GameListRep, getGameDetailApi } from "@/api/home";
 import Box from "@/components/Box";
 import { useRouter } from "@/i18n";
-import { useGlobalStore } from "@/stores";
 import { brandList } from "@/utils/constant";
+import { getToken } from "@/utils/Cookies";
 import { Button, Popup, Toast } from "antd-mobile";
 import { useTranslations } from "next-intl";
 import { FC, PropsWithChildren, ReactNode, useEffect, useRef, useState } from "react";
@@ -22,9 +22,8 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
 
     const [visible, setVisible] = useState(false);
 
-    const state = useGlobalStore();
     const router = useRouter();
-    const { token } = state;
+    const token = getToken();
     useEffect(() => {
         appRef.current! = document.querySelector("#app")!;
     }, []);