const API_URL = process.env.NEXT_PUBLIC_BACKEND_API

export async function fetchAPI(target, token) {
	var requestOptions = {
		method: 'POST',
		headers: {
			'Content-Type': 'multipart/form-data',
			Authorization: 'Bearer ' + token,
		},
		redirect: 'follow',
	}

	const res = await fetch(API_URL + target, requestOptions)

	const json = await res.json()
	if (json.errors) {
		console.error(json.errors)
		throw new Error('Failed to fetch API')
	}
	return json.data
}
