Sobes.tech
Middle

/** * La fonction `asyncAuth(callback)` accepte un callback, dans lequel peut * être passé une erreur (en premier argument) et des données * du backend (en second argument). * asyncAuth((error, data) => {}); * * Vous devez implémenter la fonction `auth()`, * qui appelle `asyncAuth()`, mais retourne une Promesse. * * @returns {Promise} */ export function auth() { // asyncAuth((error, data) => {}); }

sobes.tech IA

Réponse de l'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);
      }
    });
  });
}