"use client" import axios from "axios"; import * as React from 'react'; import { useEffect, useState } from "react"; import { useSession } from "next-auth/react"; import { cn } from "@/lib/utils"; const UserProfile = () => { const { data: session, status } = useSession(); const [user, setUser] = useState<{ id: string, username: string }>() let previousUsername = "" useEffect(() => { if (status !== "authenticated" || previousUsername == session.user?.name) { return } previousUsername = session.user?.name || "" if (session.user) { const fetchData = async () => { if (user) return let userData = (await axios.get("/api/account")).data setUser(userData) } fetchData().catch(console.error) } }, [session]) return (
Logged in as:
{user?.username}