diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 49ed0ff..ee204c7 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -1,9 +1,9 @@ -"use client"; - // import { LanguageSwitcher } from "@/components/LanguageSwitcher"; import { ModeToggle } from "@/components/ThemeSwitcher"; import { Separator } from "@/components/ui/separator"; import { Skeleton } from "@/components/ui/skeleton"; +import { fetchLoginUser } from "@/lib/nezha-api"; +import { useQuery } from "@tanstack/react-query"; import { DateTime } from "luxon"; import { useEffect, useRef, useState } from "react"; @@ -31,6 +31,7 @@ function Header() {

+ {/* */}
@@ -40,6 +41,30 @@ function Header() { ); } +function DashboardLink() { + const { data: userData } = useQuery({ + queryKey: ["login-user"], + queryFn: () => fetchLoginUser(), + refetchOnMount: true, + refetchOnWindowFocus: true, + }); + + if (!userData?.data?.id) return null; + + return ( +
+ + Dashboard + +
+ ); +} + // https://github.com/streamich/react-use/blob/master/src/useInterval.ts const useInterval = (callback: () => void, delay: number | null) => { const savedCallback = useRef<() => void>(() => {}); diff --git a/src/components/ServerDetailChart.tsx b/src/components/ServerDetailChart.tsx index a366f2c..e56ca9b 100644 --- a/src/components/ServerDetailChart.tsx +++ b/src/components/ServerDetailChart.tsx @@ -1,5 +1,3 @@ -"use client"; - import { Card, CardContent } from "@/components/ui/card"; import { ChartConfig, ChartContainer } from "@/components/ui/chart"; import { formatNezhaInfo, formatRelativeTime } from "@/lib/utils"; diff --git a/src/components/ThemeSwitcher.tsx b/src/components/ThemeSwitcher.tsx index fa248b0..b8b1384 100644 --- a/src/components/ThemeSwitcher.tsx +++ b/src/components/ThemeSwitcher.tsx @@ -1,5 +1,3 @@ -"use client"; - import { Button } from "@/components/ui/button"; import { DropdownMenu, diff --git a/src/components/motion/motion-provider.tsx b/src/components/motion/motion-provider.tsx index 84f27e8..fca4e36 100644 --- a/src/components/motion/motion-provider.tsx +++ b/src/components/motion/motion-provider.tsx @@ -1,5 +1,3 @@ -"use client"; - import { LazyMotion } from "framer-motion"; const loadFeatures = () => diff --git a/src/lib/nezha-api.ts b/src/lib/nezha-api.ts index 8964152..3a47bc8 100644 --- a/src/lib/nezha-api.ts +++ b/src/lib/nezha-api.ts @@ -1,4 +1,4 @@ -import { ServerGroupResponse } from "@/types/nezha-api"; +import { LoginUserResponse, ServerGroupResponse } from "@/types/nezha-api"; export const fetchServerGroup = async (): Promise => { const response = await fetch("/api/v1/server-group"); @@ -8,3 +8,12 @@ export const fetchServerGroup = async (): Promise => { } return data; }; + +export const fetchLoginUser = async (): Promise => { + const response = await fetch("/api/v1/profile"); + const data = await response.json(); + if (data.error) { + throw new Error(data.error); + } + return data; +}; diff --git a/src/types/nezha-api.ts b/src/types/nezha-api.ts index 9adc292..3bbc591 100644 --- a/src/types/nezha-api.ts +++ b/src/types/nezha-api.ts @@ -58,3 +58,14 @@ export interface ServerGroup { }; servers: number[]; } + +export interface LoginUserResponse { + success: boolean; + data: { + id: number; + username: string; + password: string; + created_at: string; + updated_at: string; + }; +}