Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
Acceda al valor de retorno dentro de un if anidado en .then() Promesa en javascript con axios

¿Cómo puedo acceder al valor de retorno de la función que se encuentra dentro de la promesa .then() en javascript?

 const verification = twil.verificationChecks.create({ to: phone, code: vcode }).then((verify) => { otp = verify.status; //twilio // console.log(otp); const user = finduser; if (otp === "approved") { // otp approved if (user) { //check phone find(); //find user return "user found" } else { add(); //add user return "user added" } //check phone } // otp approved }); console.log(verification) // this returns undefined return verification // this returns [ object promise ]
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Puede usar la sintaxis async...await para este problema.

 const verification = async () => { const verify = await twil.verificationChecks.create({ to: phone, code: vcode, }); otp = verify.status; //twilio // console.log(otp); const user = finduser; if (otp === 'approved') { // otp approved if (user) { //check phone find(); //find user return 'user found'; } else { add(); //add user return 'user added'; } //check phone } // otp approved };
about 4 years ago · Juan Pablo Isaza Denunciar

0

Incluso puede usar el emisor de eventos para abordar este problema

 let verifyData; let ee = new EventEmitter(); //create new event to be called after data is available const verification = () => { twil.verificationChecks .create({ to: phone, code: vcode }) .then((verify) => { verifyData = verify; ee.emit("dataFilled"); // Call event emitter otp = verify.status; //twilio // console.log(otp); const user = finduser; if (otp === "approved") { // otp approved if (user) { //check phone find(); //find user return "user found"; } else { add(); //add user return "user added"; } //check phone } // otp approved }); }; ee.on("dataFilled", function () { console.log(verifyData); // Add you code here });
about 4 years ago · Juan Pablo Isaza Denunciar

0

Hará el mismo trabajo que estás pensando..

 let verifyData; let ee = new EventEmitter(); //create new event to be called after data is available const verification = () => { twil.verificationChecks.create({ to: phone, code: vcode }).then((verify) => { otp = verify.status; //twilio // console.log(otp); const user = finduser; if (otp === "approved") { // otp approved if (user) { //check phone find(); //find user verifyData = "user found"; } else { add(); //add user verifyData = "user added"; } //check phone ee.emit("varificationDone"); // Call event emitter } // otp approved }); }; ee.on("varificationDone", function () { switch (verifyData) { case "user found": // your code here break; case "user added": // your code here break; default: break; } });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda