fix: paper page use useAuth() instead of manual localStorage check

This commit is contained in:
root 2026-02-28 11:24:29 +00:00
parent 961cbc6bd8
commit 59910fe9cd

View File

@ -1,7 +1,7 @@
"use client"; "use client";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import Link from "next/link"; import Link from "next/link";
import { authFetch } from "@/lib/auth"; import { authFetch, useAuth } from "@/lib/auth";
import { LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, ReferenceLine, Area, AreaChart } from "recharts"; import { LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, ReferenceLine, Area, AreaChart } from "recharts";
// ─── 工具函数 ──────────────────────────────────────────────────── // ─── 工具函数 ────────────────────────────────────────────────────
@ -316,11 +316,9 @@ function StatsPanel() {
// ─── 主页面 ────────────────────────────────────────────────────── // ─── 主页面 ──────────────────────────────────────────────────────
export default function PaperTradingPage() { export default function PaperTradingPage() {
const [isLoggedIn, setIsLoggedIn] = useState(false); const { isLoggedIn, loading } = useAuth();
useEffect(() => {
const token = typeof window !== "undefined" ? localStorage.getItem("token") : null; if (loading) return <div className="text-center text-slate-400 py-8">...</div>;
setIsLoggedIn(!!token);
}, []);
if (!isLoggedIn) return ( if (!isLoggedIn) return (
<div className="flex flex-col items-center justify-center h-64 gap-4"> <div className="flex flex-col items-center justify-center h-64 gap-4">