'use server';

import axios from 'axios';

import { AUTH_USER } from '@/types/interfaces';
import APIS from '@/utils/apis';
import { cache } from 'react';

const currentUrl = process.env.BASE_URL_BE || "";

export const getUserData = cache(async (token: string) => {
  try {
    const API_URL = APIS['GET_PROFILE'];
    const baseUrl = `${currentUrl}${API_URL.url}`;

    const { data } = (await axios({
      url: baseUrl,
      method: API_URL.method,
      headers: {
        Authorization: `Bearer ${token}`,
      },
    })) as { data };
    const user = data.data as AUTH_USER;
    return user;
  } catch (error) {
    console.log("getUserData", error)
    return false;
  }
});
