import { Oauth2RequestType, getOauth2RedirectURL, unbindOauth2 } from "@/api/oauth2" import { getProfile } from "@/api/user" import { ProfileCard } from "@/components/profile" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { Button } from "@/components/ui/button" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { useMainStore } from "@/hooks/useMainStore" import { useMediaQuery } from "@/hooks/useMediaQuery" import { useServer } from "@/hooks/useServer" import useSetting from "@/hooks/useSetting" import { Boxes, Server } from "lucide-react" import { useEffect } from "react" import { toast } from "sonner" export default function ProfilePage() { const { profile, setProfile } = useMainStore() const { servers, serverGroups } = useServer() const { data: settingData } = useSetting() const isDesktop = useMediaQuery("(min-width: 890px)") useEffect(() => { const oauth2 = new URLSearchParams(window.location.search).get("oauth2") if (oauth2) { getProfile().then((profile) => { setProfile(profile) }) window.history.replaceState({}, document.title, window.location.pathname) } }, [setProfile]) const bindO2 = async (provider: string) => { try { const redirectUrl = await getOauth2RedirectURL(provider, Oauth2RequestType.BIND) window.location.assign(redirectUrl.redirect!) } catch (error: any) { toast.error(error.message) } } const unbindO2 = async (provider: string) => { try { await unbindOauth2(provider) const profile = await getProfile() setProfile(profile) } catch (error: any) { toast.error(error.message) } } return ( profile && (
{profile.username}

IP: {profile.login_ip || "Unknown"}

{isDesktop && ( )}
{!isDesktop && ( )}
Servers {servers?.length || 0} Server Groups {serverGroups?.length || 0} Oauth2 bindings {settingData?.config?.oauth2_providers?.map((provider) => (

{provider}:

{profile.oauth2_bind?.[provider.toLowerCase()] && (

{profile.oauth2_bind?.[provider.toLowerCase()]}

)}
{profile.oauth2_bind?.[provider.toLowerCase()] ? ( ) : ( )}
))}
) ) }