Middle
/** * La función `asyncAuth(callback)` acepta un callback, en el cual puede * ser pasada un error (como primer argumento) y datos * del backend (como segundo argumento). * asyncAuth((error, data) => {}); * * Necesitas implementar la función `auth()`, * que llama a `asyncAuth()`, pero devuelve una Promesa. * * @returns {Promise} */ export function auth() { // asyncAuth((error, data) => {}); }
sobes.tech AI
Respuesta de la 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);
}
});
});
}