import Cookies from 'js-cookie'; const fecher = async (url: string, token: string) => { return await fetch(url, { method: "GET", headers: { "Content-Type": "application/json", "Authorization":token }, }); } export const useFetchWithAuth = async (url: string) => { url= process.env.API_URL+"/api/"+url+"/"; const token = Cookies.get('token') || ""; let data; let error; try{ const response = await fecher(url, token) if (response.ok){ data = await response.json(); }else { console.log(url) error = "Servidor: "+ ((await response.json()).trace); } }catch (e){ error = "Cliente: "+e; } return { data, error } }