e-verify/lib/fetch.js

22 lines
470 B
JavaScript
Raw Normal View History

2024-05-14 22:19:14 +07:00
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
}