Sobes.tech
Middle

/** * A função `asyncAuth(callback)` aceita um callback, no qual pode * ser passada uma erro (como primeiro argumento) e dados * do backend (como segundo argumento). * asyncAuth((error, data) => {}); * * Precisa implementar a função `auth()`, * que chama `asyncAuth()`, mas retorna uma Promessa. * * @returns {Promise} */ export function auth() { // asyncAuth((error, data) => {}); }

sobes.tech IA

Resposta da IA

Чтобы обернуть функцию с callback в Promise, нужно внутри auth создать и вернуть новый Promise, в котором вызвать asyncAuth и в callback вызвать resolve или reject.

export function auth() {
  return new Promise((resolve, reject) => {
    asyncAuth((error, data) => {
      if (error) {
        reject(error);
      } else {
        resolve(data);
      }
    });
  });
}