"use Client"; import React, { useState, useEffect } from "react"; import { checkAuth, signOut } from "@/utils/auth"; import { getCookie } from "cookies-next"; import { useRouter } from "next/navigation"; export default function AuthBar({ onNotLoginedClick = () => {} }) { const router = useRouter(); const [isLogined, setIsLogined] = useState(); const [cookies, setCookies] = useState(); const [showDetail, setShowDetail] = useState(false); useEffect(() => { const prepare = async () => { const tempIsLogined = await checkAuth(); const accountCookie = getCookie("account"); const account = accountCookie == undefined ? {} : JSON.parse(accountCookie); setIsLogined(tempIsLogined); setCookies(account); }; prepare(); }, []); //退出登录 const handleSignOut = () => { signOut(); window.location.reload(); }; //点击登录 const handleSignIn = () => { onNotLoginedClick(); router.push("/auth/login/phonenumlogin"); }; //点击已购 const handlePurchased = () => { router.push("/purchased"); }; return (
{isLogined ? (
setShowDetail(!showDetail)} className="flex flex-col cursor-pointer bg-[#FFFFFF1A] rounded-full px-4 py-2" >

{cookies?.name}

已购

登出

) : (

点击登录

)}
); }