"use client" import axios from "axios"; import * as React from 'react'; import { User } from "@prisma/client"; import { useEffect, useState } from "react"; import { useSession } from "next-auth/react"; import { usePathname } from 'next/navigation' import { cn } from "@/lib/utils"; const UserProfile = () => { const { data: session, status } = useSession(); const [previousUsername, setPreviousUsername] = useState() const [user, setUser] = useState() const [loading, setLoading] = useState(true) const pathname = usePathname() useEffect(() => { if (status !== "authenticated" || previousUsername == session.user?.name) { return } setPreviousUsername(session.user?.name as string) if (session.user) { const fetchData = async () => { var userData: User = (await axios.get("/api/account")).data setUser(userData) setLoading(false) } fetchData().catch(console.error) // TODO: check cookies if impersonation is in use. } }, [session]) return (

Logged in as:

{user?.username}

); } export default UserProfile;