"use client";

import { useState, useEffect } from "react";
import { User } from "@/types/types";
import useAxios from "./useAxios";

export const useUser = () => {
  const [user, setUser] = useState<User>();
  const { request } = useAxios();
  const fetchUser = async () => {
    try {
      const response = await request<{ user: User }>("GET", "/profile");
      setUser(response?.user);
    } catch (error) {
      console.error("Failed to fetch user:", error);
    }
  };
  useEffect(() => {
    fetchUser();
  }, []);

  return user;
};
