import type {LoginRequest} from "../dtos/LoginRequest.ts";
import type {LoginResponse} from "../dtos/LoginResponse.ts";
import {postJson} from "../utils/requests";


/**
 * Util for handling the recipe api
 */
// read base url from .env file
const BASE_URL = import.meta.env.VITE_API_BASE;

/**
 * URL for handling recipes
 */
const AUTH_URL = `${BASE_URL}/auth`


/**
 * Login to recipe app
 * @param loginRequest Login Requets
 * @returns LoginResponse
 */
export async function login(loginRequest: LoginRequest): Promise<LoginResponse> {
    const res = await postJson(`${AUTH_URL}/login`, JSON.stringify(loginRequest), false);
    return res.json();
}
