/* eslint-disable import/prefer-default-export */
import type { AxiosRequestConfig } from 'axios';
import axios from 'axios';
import { love } from './tools';
import type { User } from './types';

// prettier-ignore
const uri = typeof window === 'undefined'
    ? process.env.NEXT_PUBLIC_URL_GET_USER_DIRECT
    : process.env.NEXT_PUBLIC_URL_GET_USER_PROXY;

export async function getUser(config: AxiosRequestConfig) {
  const user = await axios.get<User>(uri!, config).then((res) => love(res.data));

  return user;
}
