async function getToken(credentials) {
const authResponse = await authenticated(credentials);
const authData = Object.create(null);
const createdAt = Date.now();
authData.accessToken = authResponse.data?.access_token;
authData.createdAt = createdAt;
console.log(authData)
return authData
}
const GNRequest = async (credentials) => {
const { accessToken, createdAt } = await getToken(credentials);
const compareDate = addHours(createdAt, 1)
if (isAfter(Date.now(), compareDate)) {
console.log('chamou a função')
return getToken(credentials)
}
return axios.create({
baseURL: process.env.GN_ENDPOINT,
httpsAgent: agent,
headers: {
Authorization: Bearer ${accessToken},
'Content-Type': 'application/json'
}
});
};