Sobes.tech
Middle

/** * La funzione `asyncAuth(callback)` accetta un callback, nel quale può * essere passata un errore (come primo argomento) e dati * dal backend (come secondo argomento). * asyncAuth((error, data) => {}); * * Devi implementare la funzione `auth()`, * che chiama `asyncAuth()`, ma restituisce una Promise. * * @returns {Promise} */ export function auth() { // asyncAuth((error, data) => {}); }

sobes.tech AI

Risposta dell'AI

Чтобы обернуть функцию с 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);
      }
    });
  });
}