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

266
Vistas
Variable cannot access outside .then()

I am trying to set a authenticator for my local application. Found that I am not able to access my var outside my .then() method

var authenticated = false;
Auth.findtheUser({
}).then(user => {
  verified= user.name.verified;
  console.log("authenticated11", verified)
}
).catch(err => console.log(err));
console.log("authenticated", verified)

the output for authenticated11 output comes as true but not the one at the end Could anyone help me out on this. New to javascript.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You cant use the result of an asynchronous function directly after it in JS. See this question: How to return the response from an asynchronous call

about 4 years ago · Juan Pablo Isaza Denunciar

0

According to what you described in a comment in this answer. You are facing an exception related to the scope.

var authenticated = false;
Auth.findtheUser({
  }).then(user => {
    verified= user.name.verified;
    console.log("authenticated11", verified)
}
).catch(err => console.log(err));
// This will throw an exception because verified does not exist in this scope
console.log("authenticated", verified)

You should change that to this

var authenticated = false;
var verified;
Auth.findtheUser({
  }).then(user => {
    verified= user.name.verified;
    console.log("authenticated11", verified)
}
).catch(err => console.log(err));
// This will throw an exception because verified does not exist in this scope
console.log("authenticated", verified)
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